Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scala/Serializable NoClassDefFoundError (RMI w/ Scala)

Been following this tutorial on RMI for Java, trying to translate it to Scala. Instead of interface I use trait, and I annotate methods to indicate the throwing of the RemoteException.

Got everything implemented, and got to the compilation step and followed it exactly, except instead of javac I used scalac.

Finally at the exciting last step, running it, and I setup the security policies, start the rmiregistry, go to startup my server and get hit with this:

java.rmi.ServerError: Error occurred in server thread; nested exception is: 
    java.lang.NoClassDefFoundError: scala/Serializable

What could be causing this? I changed their command from java to scala, but everything else is the same (modulo the usernames and file paths).. how is it not finding scala/Serializable?

Potentially relevant:

$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.4) (rhel-1.49.1.11.4.el6_3-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

$ scala -version
Scala code runner version 2.9.2 -- Copyright 2002-2011, LAMP/EPFL

UPDATE: Replaced scala.Serializable with java.io.Serializable and everything worked. However, this is a work around the problem and opposed to solving the problem. According to the Scala API, scala.Serializable extends java.io.Serializable so something is going wonky with the classpath...

like image 623
adelbertc Avatar asked Oct 03 '12 06:10

adelbertc


1 Answers

Scala compiles code down to Java classes, but when you're using the standard library in any way, you also need to include the Scala runtime library in your classpath.

In other words, you'll need /path/to/scala-library.jar in the -cp argument of your java invocation.

like image 126
themel Avatar answered Nov 10 '22 22:11

themel