找不到编译器镜像中的对象scala - 以编程方式运行Scala编译器[没有sbt - 没有IDE]

时间:2015-06-18 09:41:18

标签: scala scalac scala-compiler

[编辑:在评论中添加精确度]

我试图以编程方式运行编译器并在编译器镜像中获得"缺少依赖项'对象scala""错误。 我找到了这篇文章object scala in compiler mirror not found - running Scala compiler programatically(但它只解释了如果我们从sbt启动程序而不是从外部启动程序,如何解决问题。)

所以我在这里复制/粘贴示例:

import scala.tools.nsc.{ Global, Settings }

object Playground extends App {
  val compiler = new Global(new Settings())
  val testFiles = List("Test.scala")
  val runner = new compiler.Run()
  val result = runner.compile(testFiles)
  println(result)
}

以及从SBT发起时使其工作的解决方案:

trait Probe

object Playground extends App {
  //val compiler = new Global(new Settings())
  val s = new Settings()
  s.embeddedDefaults[Probe]
  val compiler = new Global(s)
  val testFiles = List("Test.scala")
  val runner = new compiler.Run()
  val result = runner.compile(testFiles)
  println(result)
}

我试图通过从sbt传递classpath的fullClassPath值直接从终端启动这两个版本:

java -cp /home/lorilan/path-to-my-project/target/scala-2.11/classes:/home/lorilan/.ivy2/c‌​ache/org.scala-lang/scala-compiler/jars/scala-compiler-2.11.6.jar:/home/lorilan/.‌​ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.6.jar:/home/loril‌​an/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.11.6.jar p.Playground 

其中java -version提供

java version "1.7.0_79" 
OpenJDK Runtime Environment (IcedTea 2.5.5) (Arch Linux build 7.u79_2.5.5-1-x86_64)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode) 

每次我收到以下错误:

error: error while loading Object, Missing dependency 'object scala in compiler mirror', required by /usr/lib/jvm/java-7-openjdk/jre/lib/rt.jar(java/lang/Object.class)
Exception in thread "main" scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.
at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:17)
at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:18)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:53)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:66)
at scala.reflect.internal.Mirrors$RootsBase.getPackage(Mirrors.scala:173)
at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage$lzycompute(Definitions.scala:161)
at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage(Definitions.scala:161)
at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass$lzycompute(Definitions.scala:162)
at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass(Definitions.scala:162)
at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1392)
at scala.tools.nsc.Global$Run.<init>(Global.scala:1216)
at puck.Playground$.main(Playground.scala:15)
at puck.Playground.main(Playground.scala)

所以我的问题有两个:

  • 有人可以向我解释一下&#34;魔术技巧的作用是什么?在上述帖子中显示? (我没有得到embeddedDefaults方法的评论)

  • 有人能给出一个同样神奇的技巧来从终端运行游乐场吗?

0 个答案:

没有答案