我正在嘗試使用我在各種網站上發現的一些信息編寫一個基本的Scala REPL。我最基本的REPL實施看起來是這樣的,自定義Scala REPL問題
import scala.tools.nsc.Settings
import scala.tools.nsc.interpreter._
object BillyREPL extends App {
val settings = new Settings
settings.usejavacp.value = true
settings.deprecation.value = true
new ILoop().process(settings)
}
用下面的構建設置,
import sbt._
import sbt.Keys._
object BillyREPLBuild extends Build {
lazy val billyrepl = Project(
id = "billyrepl",
base = file("."),
settings = Project.defaultSettings ++ Seq(
name := "BillyREPL",
organization := "tv.yobriefcasts",
version := "0.1-SNAPSHOT",
scalaVersion := "2.10.1",
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % "2.10.1",
"org.scala-lang" % "scala-library" % "2.10.1"
)
)
)
}
嘗試運行然而,這導致了一些警告和最終的錯誤(這我相信由最初所引起警告),
Welcome to Scala version 2.10.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_12-ea).
Type in expressions to have them evaluated.
Type :help for more information.
scala>
Failed to initialize compiler: object scala.annotation.Annotation 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.
而試圖讀取/評估ANYING時的錯誤如下。我不確定這是否是由於一些額外的缺失依賴,並且我意識到錯誤消息表明這是不常見的,但是我想知道如果有人之前曾經處理過這個問題,是否在我打開問題之前?
2
Failed to initialize the REPL due to an unexpected error.
This is a bug, please, report it along with the error diagnostics printed below.
java.lang.NullPointerException
at scala.tools.nsc.interpreter.ExprTyper$codeParser$.applyRule(ExprTyper.scala:24)
at scala.tools.nsc.interpreter.ExprTyper$codeParser$.stmts(ExprTyper.scala:35)
at scala.tools.nsc.interpreter.ExprTyper$$anonfun$parse$2.apply(ExprTyper.scala:43)
at scala.tools.nsc.interpreter.ExprTyper$$anonfun$parse$2.apply(ExprTyper.scala:42)
at scala.tools.nsc.reporters.Reporter.withIncompleteHandler(Reporter.scala:51)
at scala.tools.nsc.interpreter.ExprTyper$class.parse(ExprTyper.scala:42)
at scala.tools.nsc.interpreter.IMain$exprTyper$.parse(IMain.scala:1074)
at scala.tools.nsc.interpreter.IMain.parse(IMain.scala:1078)
at scala.tools.nsc.interpreter.IMain$$anonfun$showCodeIfDebugging$1.apply(IMain.scala:1168)
at scala.tools.nsc.interpreter.IMain$$anonfun$showCodeIfDebugging$1.apply(IMain.scala:1168)
at scala.tools.nsc.interpreter.IMain.beSilentDuring(IMain.scala:238)
at scala.tools.nsc.interpreter.IMain.showCodeIfDebugging(IMain.scala:1168)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compileAndSaveRun(IMain.scala:800)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compile(IMain.scala:761)
at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:618)
at scala.tools.nsc.interpreter.IMain.bind(IMain.scala:661)
at scala.tools.nsc.interpreter.IMain$$anonfun$quietBind$1.apply(IMain.scala:660)
at scala.tools.nsc.interpreter.IMain$$anonfun$quietBind$1.apply(IMain.scala:660)
at scala.tools.nsc.interpreter.IMain.beQuietDuring(IMain.scala:232)
at scala.tools.nsc.interpreter.IMain.quietBind(IMain.scala:660)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1$$anonfun$apply$mcZ$sp$2.apply$mcV$sp(ILoop.scala:838)
at scala.tools.nsc.interpreter.ILoopInit$class.runThunks(ILoopInit.scala:122)
at scala.tools.nsc.interpreter.ILoop.runThunks(ILoop.scala:42)
at scala.tools.nsc.interpreter.ILoopInit$class.postInitialization(ILoopInit.scala:95)
at scala.tools.nsc.interpreter.ILoop.postInitialization(ILoop.scala:42)
at scala.tools.nsc.interpreter.ILoopInit$$anonfun$createAsyncListener$1.apply$mcV$sp(ILoopInit.scala:63)
at scala.tools.nsc.interpreter.ILoopInit$$anonfun$createAsyncListener$1.apply(ILoopInit.scala:60)
at scala.tools.nsc.interpreter.ILoopInit$$anonfun$createAsyncListener$1.apply(ILoopInit.scala:60)
at scala.tools.nsc.io.package$$anon$3.call(package.scala:40)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
.
是否經由'SBT開始你的項目run',因爲推出定製來自sbt的口譯員不工作AFAIK。如果是這種情況,請嘗試使用sbt-assembly構建獨立程序,並查看是否正確啓動。 –
啊,就是這樣。你想發佈這個答案,所以我可以接受它嗎? –