简体   繁体   中英

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. I've seen this very interesting question but it does not seem to be working in Eclipse (3.5.2 + Scala plugin).

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. What could be wrong? Something with Eclipse?

Thanks!

PS: here is a simplified version of what I am trying to make work

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).

If that's the case then a pristine install of the Eclipse tooling for 2.8.0.final should resolve the issue for you. If it doesn't then you've probably found a bug in the SDT and you should report it here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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