Play 2.1中的scala.tools.nsc.IMain
我google了很多,现在完全陷入困境.我知道,有类似的问题,但请读到最后.我已经尝试了所有提出的解决方
我试图在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发送了一些内容,就会发现以下错误: 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( ) } 到目前为止我尝试了什么 这一切都行不通: >我在Build.scala中包含了fork:= true > embeddedDefaults [MyType] >灵魂提出了对问题Embedded Scala REPL inherits parent classpath的回答 我现在不知道该怎么做. 解决方法
这里的问题是sbt没有将scala-library添加到类路径中.
以下解决方法有效. 首先在顶部项目目录(app的父级,conf等)中创建一个文件夹lib,然后在那里复制scala-library.jar 然后,您可以使用以下代码来托管解释器: val settings = new Settings settings.bootclasspath.value +=scala.tools.util.PathResolver.Environment.javaBootClassPath + File.pathSeparator + "lib/scala-library.jar" val in = new IMain(settings){ override protected def parentClassLoader = settings.getClass.getClassLoader() } val res = in.interpret("val x = 1") 上面通过向scala库添加scala库来创建bootclasspath.它不是来自sbt的游戏框架的问题.当它与sbt一起运行时,任何scala项目都会出现同样的问题.测试了一个简单的项目.当它从eclipse运行时它的工作正常. 编辑:Link to sample project demonstrating the above.` (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |