4

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)
  }
}
Community
  • 1
  • 1
user406752
  • 41
  • 1
  • I can't make it work with Eclipse but it does work if I launch the executable with the "scala" command... just like this: "scala packageName.classWithMain" for instance: "scala userInterface.controller" Replace your own package name and class! The problem is that Eclipse invokes the program using the "java" executable, not "scala". I do not know how to modify this behavior. – user406752 Jul 31 '10 at 00:32
  • 1
    The problem might be the same as what's mentioned in the comments on that other question: Eclipse launches the process with `java -classpath ...` instead of `scala -classpath ...`. Try adding `scala-compiler.jar` to the classpath and see if it works. – Jesper Jul 31 '10 at 05:31
  • I tried that but still the command Eclipse uses is java, not scala (I can see it in the Debugger view). So far the solution is to use the command line. – user406752 Jul 31 '10 at 13:10
  • 1
    @stephan did you try adding `scala-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 with `java` instead of `scala`. – Jesper Jul 31 '10 at 21:12
  • @stephan Indeed, if you open `scala` with an editor you'll see it's just a shell script which calls `java`. So the only difference is what is in the classpath. – Daniel C. Sobral Aug 05 '10 at 22:47

1 Answers1

1

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.

Miles Sabin
  • 23,015
  • 6
  • 61
  • 95
  • Yes, it's Scala 2.8 (break(Nil) is only supported in 2.8 as far as I know). I'm not sure it is a bug since the compiled binaries work fine in the command line: they just need to be launched with the "scala" command, not with "java" (as Eclipse does). – user406752 Jul 31 '10 at 13:11
  • What kind of launch are you doing in Eclipse? Are you running as a Scala application with the Scala IDE for Eclipse? – Miles Sabin Jul 31 '10 at 16:38