如何在 Simple Build Tool 项目中调用 scala 解释器?

发布于 2024-11-15 11:36:25 字数 946 浏览 5 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黄昏下泛黄的笔记 2024-11-22 11:36:25
sbt console // Starts a Scala interpreter

这是新的常见问题解答(以前的答案已过时)

http:// www.scala-sbt.org/0.12.4/docs/faq.html

您还可以找到最新版本的常见问题解答。
请注意,sbt console-quick 加载没有依赖项的控制台。

sbt console // Starts a Scala interpreter

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.

漆黑的白昼 2024-11-22 11:36:25

看一下 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.

帅气尐潴 2024-11-22 11:36:25

在较新的 sbt 版本(0.12 及更高版本)中,以下内容应该足够了:

fork in run := true

In more recent sbt versions (0.12 and newer), the following should suffice:

fork in run := true
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文