如何在简单构建工具项目中调用scala解释器? [英] How to call the scala interpreter in a Simple Build Tool project?

查看:234
本文介绍了如何在简单构建工具项目中调用scala解释器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的scala程序正在使用来自scala.tools.nsc.interpreter.IMain的编译器接口.当我使用scalac进行编译时,一切都会按预期进行.但是,当我使用sbt进行编译时,它仍然可以编译,但是在执行时,它会从IMain实例的解释方法调用中引发以下错误消息:

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.

如果我在IMain实例上使用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>

我的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"
}

这是怎么了?以及如何在简单构建工具项目中使用解释器?

What's wrong here? And how can I use the interpreter in a Simple Build Tool Project?

我正在使用 Scala 2.9.0 简单构建工具0.7.7

推荐答案

看看SBT Wiki:

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.

这篇关于如何在简单构建工具项目中调用scala解释器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆