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) } }
java -classpath ...
instead ofscala -classpath ...
. Try addingscala-compiler.jar
to the classpath and see if it works. – Jesperscala-compiler.jar
to the classpath of your project in Eclipse? Then it should work (although I didn't try myself), even when the program is started withjava
instead ofscala
. – Jesperscala
with an editor you'll see it's just a shell script which callsjava
. So the only difference is what is in the classpath. – Daniel C. Sobral