【发布时间】:2013-05-06 20:21:36
【问题描述】:
我用谷歌搜索了很多,现在完全卡住了。我知道,有类似的问题,但请阅读到最后。我已经尝试了所有建议的解决方案,但都没有奏效。
我正在尝试在 Play 2.1 项目中使用来自 scala.tools.nsc 的 IMain 类(使用 Scala 2.10.0)。
控制器代码
这是代码,我尝试在 Websocket 中使用IMain。这仅用于测试。
object Scala extends Controller {
def session = WebSocket.using[String] { request =>
val interpreter = new IMain()
val (out,channel) = Concurrent.broadcast[String]
val in = Iteratee.foreach[String]{ code =>
interpreter.interpret(code) match {
case Results.Error => channel.push("error")
case Results.Incomplete => channel.push("incomplete")
case Results.Success => channel.push("success")
}
}
(in,out)
}
}
一旦通过 Websocket 发送某些内容,play 就会记录以下错误:
Failed to initialize compiler: object scala.runtime 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.
Build.scala
object ApplicationBuild extends Build {
val appName = "escalator"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
"org.scala-lang" % "scala-compiler" % "2.10.0"
)
val main = play.Project(appName, appVersion, appDependencies).settings(
)
}
到目前为止我所尝试的
这一切都不起作用:
- 我已将
fork := true包含在Build.scala中 -
Settings对象具有:embeddedDefaults[MyType]usejavacp.value = true
- 建议作为问题Embedded Scala REPL inherits parent classpath的答案
我现在不知道该怎么办。
【问题讨论】:
-
你有没有尝试过更简单的方法,比如 (new scala.tools.nsc.interpreter.IMain()).interpret("val x = 1") match ...
-
@Iraklis 是的。我把它放在 Global.scala 的初始化代码中。同样的错误信息。
-
您可能还想看看我对这个问题的回答here。
标签: scala playframework-2.0 classpath read-eval-print-loop