我正在尝试在 InteliJ IDEA Scala Worksheet (Scala 2.11.2) 中运行 Scala ScriptEngine
下一个代码:
import javax.script.ScriptEngineManager
val e = (new ScriptEngineManager()).getEngineByName("scala")
e.eval("1 to 10 foreach println")
抛出错误:
e: javax.script.ScriptEngine = scala.tools.nsc.interpreter.IMain@49049a04
[init] error: error while loading Object, Missing dependency 'object scala in compiler mirror', required by C:\Program Files\Java\jdk1.8.0_11\jre\lib\rt.jar(java/lang/Object.class)
Failed to initialize compiler: object scala in compiler mirror not found.
** Note that as of 2.8 scala does not assume use of the java classpath.
** For the old behavior pass -usejavacp to scala, or if using a Settings
** object programatically, settings.usejavacp.value = true.
scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.
at scala.reflect.internal.MissingRequirementError$.signal(D:/workspace/Poster/src/test.sc:13)
at scala.reflect.internal.MissingRequirementError$.notFound(D:/workspace/Poster/src/test.sc:14)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(D:/workspace/Poster/src/test.sc:49)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(D:/workspace/Poster/src/test.sc:62)
at scala.reflect.internal.Mirrors$RootsBase.getPackage(D:/workspace/Poster/src/test.sc:169)
at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage$lzycompute(D:/workspace/Poster/src/test.sc:157)
at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage(D:/workspace/Poster/src/test.sc:157)
at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass$lzycompute(D:/workspace/Poster/src/test.sc:158)
at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass(D:/workspace/Poster/src/test.sc:158)
at scala.reflect.internal.Definitions$DefinitionsClass.init(D:/workspace/Poster/src/test.sc:1373)
at scala.tools.nsc.Global$Run.<init>(D:/workspace/Poster/src/test.sc:1225)
at scala.tools.nsc.interpreter.IMain.compileSourcesKeepingRun(D:/workspace/Poster/src/test.sc:384)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compileAndSaveRun(D:/workspace/Poster/src/test.sc:803)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compile(D:/workspace/Poster/src/test.sc:762)
at scala.tools.nsc.interpreter.IMain.bind(D:/workspace/Poster/src/test.sc:626)
at scala.tools.nsc.interpreter.IMain.bind(D:/workspace/Poster/src/test.sc:663)
at scala.tools.nsc.interpreter.IMain$$anonfun$quietBind$1.apply(D:/workspace/Poster/src/test.sc:662)
at scala.tools.nsc.interpreter.IMain$$anonfun$quietBind$1.apply(D:/workspace/Poster/src/test.sc:662)
at #worksheet#.#worksheet#(D:/workspace/Poster/src/test.sc:200)
build.sbt 如下:
name := "Poster"
version := "1.0"
libraryDependencies += "org.seleniumhq.selenium" % "selenium-java" % "2.42.2"
libraryDependencies += "org.scala-lang" % "scala-compiler" % "2.11.2"
libraryDependencies += "org.scala-lang" % "scala-library" % "2.11.2"
包括所有需要的依赖项,我不明白为什么它不起作用。
Eclipse Luna + Eclipse IDE 4 中的相同项目工作正常!
如何在 InteliJ IDEA 中运行它?