简体   繁体   English

在执行Scala程序期间放入Scala解释器

[英]Drop into Scala interpreter during execution of Scala program

I am trying to drop into the Scala interpreter in the middle of my Scala program. 我试图在我的Scala程序中插入Scala解释器。 I've seen this very interesting question but it does not seem to be working in Eclipse (3.5.2 + Scala plugin). 我已经看到了这个非常有趣的问题,但它似乎不适用于Eclipse(3.5.2 + Scala插件)​​。

I get the following error: 我收到以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: scala/io/LowPriorityCodecImplicits
    at scala.tools.nsc.Interpreter$.breakIf(Interpreter.scala:1265)
    at userInterface.CommandInterpreter$$anonfun$main$1.apply$mcVI$sp(CommandInterpreter.scala:102)
    at scala.collection.immutable.Range$ByOne$class.foreach$mVc$sp(Range.scala:275)
    at scala.collection.immutable.Range$$anon$1.foreach$mVc$sp(Range.scala:267)
    at userInterface.CommandInterpreter$.main(CommandInterpreter.scala:101)
    at userInterface.CommandInterpreter.main(CommandInterpreter.scala)
Caused by: java.lang.ClassNotFoundException: scala.io.LowPriorityCodecImplicits
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    ... 6 more

The very same code works if I compile it with scalac and run it on my terminal. 如果我用scalac编译它并在我的终端上运行它,那么相同的代码就可以工作了。 What could be wrong? 可能有什么不对? Something with Eclipse? Eclipse的东西?

Thanks! 谢谢!

PS: here is a simplified version of what I am trying to make work PS:这是我正在努力工作的简化版本

import scala.tools.nsc.Interpreter._
object ScalaShell {
  def main(args: Array[String]) {
    break(Nil)
  }
}

You don't mention the versions of the Scala command-line tools or the Scala IDE for Eclipse that you're using, but I'll stick my neck out and guess that the command line tools are 2.8.0 whereas the Eclipse tooling is 2.7.x or you have a 2.7.x scala-library .jar somewhere on your Eclipse projects classpath (maybe pulled in via a Maven dependency). 您没有提到您正在使用的Scala命令行工具或Scala IDE for Eclipse的版本,但我会坚持认为命令行工具是2.8.0而Eclipse工具是2.7.x或者你在Eclipse项目类路径上的某个地方有一个2.7.x scala-library .jar(可能是通过Maven依赖项引入的)。

If that's the case then a pristine install of the Eclipse tooling for 2.8.0.final should resolve the issue for you. 如果是这种情况,那么为2.8.0.final安装Eclipse工具应该为您解决问题。 If it doesn't then you've probably found a bug in the SDT and you should report it here . 如果没有,那么你可能在SDT中发现了一个错误,你应该在这里报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM