我必须在 Play Framework 应用程序中使用 scala 解析器。
import scala.tools.nsc._
trait Foo
class Parser {
def parse(code: String) = {
val settings = new Settings
settings.embeddedDefaults[Foo]
val interpreter = new Interpreter(settings)
interpreter.parse(code)
}
}
我在 Build.scala 中有以下依赖项
"org.scala-lang" % "scala-compiler" % "2.9.1"
此代码在使用 SBT 构建时有效。在 Play 中,它以 NullPointerException 结束,并且:
无法初始化编译器:找不到对象 scala。
** 请注意,从 2.8 开始,scala 不假定使用 java 类路径。
** 对于旧行为,将 -usejavacp 传递给 scala,或者如果使用设置
** 对象编程,settings.usejavacp.value = true。
构建.scala
import sbt._
import Keys._
import PlayProject._
object ApplicationBuild extends Build {
val appName = "com.qwerty.utils"
val appVersion = "1.0-SNAPSHOT"
val scalaVersion = "2.9.1"
val appDependencies = Seq(
"org.scala-lang" % "scala-compiler" % "2.9.1"
)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
// Add your own project settings here
)
}