我正在尝试使用以下代码以编程方式调用scala解释器
val settings = new Settings()
settings.usejavacp.value = true
settings.embeddedDefaults[Probe]
classPath.map(settings.classpath.prepend(_))
classPath.map(settings.bootclasspath.prepend(_))
settings.withErrorFn(err => println(s"error while compiling $err"))
val compile = new Global(settings)
val run = new compile.Run
val sourceFiles = run.compile("Test.scala")
Test.scala看起来像
class Test {
println ("Hello World!")
}
build.sbt依赖项看起来像
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % "2.11.7",
"org.scala-lang" % "scala-library" % "2.11.7",
"org.scala-lang" % "scala-reflect" % "2.11.7"
)
并收到以下错误
[error] (run-main-1e) scala.reflect.internal.FatalError: class StringContext does not have a member f
我已经尝试过预先添加scala-reflect-2.11.7.jar和scala-library-2.11.7.jar,但似乎没有任何工作
答案 0 :(得分:0)
删除settings.usejavacp.value = true
,这应该有帮助。
PS:不需要Probe
,您可以使用settings.embeddedDefaults(getClass.getClassLoader)