[英]invoking scala interpreter programmatically
我試圖使用以下代碼以編程方式調用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,但似乎什么也沒做
刪除settings.usejavacp.value = true
,這應該有幫助。
PS:不需要Probe
,你可以只使用settings.embeddedDefaults(getClass.getClassLoader)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.