RSS Feed for This PostCurrent Article

Java RMI Programming – RemoteException … ClassNotFoundException


When I am doing some RMI programming for Java, I encountered the following error

Error starting the server: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: com.xx.xx

A search through Web revealed many results that describe how the error can happen.

A Java property “java.rmi.server.codebase” must be set when you want to run the Java program.

What is not clear is that your code base can be pointing to Jar file or compiled classes in the server where “rmiregistry” is run, not where your Java program is running, or alternatively pointing to a HTTP server where your compiled classes or Jar file is installed.

E.g.

You started your RMI registry in Server A, and you tried to start your RMI server in Server B, and you encountered the above error.

What I noticed is that when I started the RMI server, it is trying to get the RMI stub based on the java.rmi.server.codebase propertyafter binding to the RMI registry. SO java.rmi.server.codebase must be pointing to the filesystem in which RMI registry is run. Alternatively, specify a HTTP url for the compiled classes, or Jar files.

E.g.

java -Djava.rmi.server.codebase=file:/c:/mycode/classes/

Take note “c:/mycode/classes” must exist in Server A, not Server B where you RMI server is supposed to run.

Alternatively, use

java -Djava.rmi.server.codebase=http://localhost:8080/myclasses


Trackback URL


Sorry, comments for this entry are closed at this time.