如何在 Simple Build Tool 项目中调用 scala 解释器?
我的 scala 程序正在使用 scala.tools.nsc.interpreter.IMain 的编译器接口。当我用 scalac 编译时,一切都按预期进行。但是,当我使用 sbt 编译时,它仍然可以编译,但在执行时,它会在从 IMain 实例调用解释方法时抛出以下错误消息:
Failed to initialize compiler: object scala 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.
如果我在 IMain 实例上使用 settings.usejavacp.value = true,我会得到以下异常:
java.lang.Error: typeConstructor inapplicable for <none>
我的 SBT 项目定义:
class Project(info: ProjectInfo) extends DefaultProject(info){
val scalaSwing = "org.scala-lang" % "scala-swing" % "2.9.0"
val scalaCompiler = "org.scala-lang" % "scala-compiler" % "2.9.0"
}
这里出了什么问题?如何在简单构建工具项目中使用解释器?
我正在使用 Scala 2.9.0 和 简单构建工具 0.7.7
my scala program is using the compiler interface from scala.tools.nsc.interpreter.IMain. When I am compiling with scalac, everything works as expected. But when I compile with sbt it still compiles, but on execution it throws the following error message in the call of the interpret-method from the IMain instance:
Failed to initialize compiler: object scala 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.
If I use settings.usejavacp.value = true on the IMain instance, I get the following exception:
java.lang.Error: typeConstructor inapplicable for <none>
My SBT project definition:
class Project(info: ProjectInfo) extends DefaultProject(info){
val scalaSwing = "org.scala-lang" % "scala-swing" % "2.9.0"
val scalaCompiler = "org.scala-lang" % "scala-compiler" % "2.9.0"
}
What's wrong here? And how can I use the interpreter in a Simple Build Tool Project?
I'm using Scala 2.9.0 and Simple Build Tool 0.7.7
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是新的常见问题解答(以前的答案已过时)
http:// www.scala-sbt.org/0.12.4/docs/faq.html
您还可以找到最新版本的常见问题解答。
请注意,
sbt console-quick
加载没有依赖项的控制台。Here is the new FAQ (the previous answer is obsolete)
http://www.scala-sbt.org/0.12.4/docs/faq.html
You can find also the FAQ for more recent versions.
Note that
sbt console-quick
loads the console without the dependencies.看一下 SBT wiki:http://www.scala-sbt.org/0.13/docs/Faq.html#How+do+I+use+the+Scala+interpreter+in+my+code%3F
有一个关于让解释器运行的条目。
Take a look at the SBT wiki: http://www.scala-sbt.org/0.13/docs/Faq.html#How+do+I+use+the+Scala+interpreter+in+my+code%3F
There's an entry about getting the interpreter running.
在较新的 sbt 版本(0.12 及更高版本)中,以下内容应该足够了:
In more recent sbt versions (0.12 and newer), the following should suffice: