Q: Exception in my RMI server - what should I do?

This is the place where you can find answers to the most frequently asked questions

Q: Exception in my RMI server - what should I do?

Postby genady » Thu Apr 27, 2006 2:11 pm

Question: I get the following exception, can you explain?

(When stubs were generated, e.g., with JDK 1.4.2)
Code: Select all
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
   java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
   java.lang.ClassNotFoundException: demo.rmi.printers.server.RemotePrinterImpl_Stub

(With Java5.0, using dynamic stubs generation)
Code: Select all
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
   java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
   java.lang.ClassNotFoundException: demo.rmi.printers.server.RemotePrinter

Answer: The most common cause to this exception is misconfigured codebase.

The RMI registry must be able to access the stubs of the registered objects and when dynamic proxies are used in Java 5.0, the registry must be able to access their remote interfaces. Normally the RMI registry has no explicit access to the server code (no CLASSPATH) and therefore it must rely on the exported codebase property when it tries to load the server classes. The exception above occurs when the rmi registry cannot locate these classes.
The solution to this problem is to export the server's codebase. If you are launching your RMI Application from a command line, you should launch it with a codebase property:
Code: Select all
java -Djava.rmi.server.codebase="<urls of your server classes>" mypack.MyClass

URL entries are separated by spaces (spaces in the filename must be replaced with "%20"). Local urls must be in the "file:/" form.

While using the codebase property on the command line is not intuitive and error prone, it is much easier to manage the application's codebase with the RMI Plugin for Eclipse. When you launch your server application using the Run As->RMI Application command, open your server's launch configuration (using Run->Run... menu option) and go to the RMI Properties tab:
Image

Then open the Codebase editor by editing the codebase property and pressing on the "..." button:

Image
Now you can configure your server's codebase. In local development environments you can just click on the "Compute from Classpath" button.

Now you can run your server and the registry will successfully locate all your classes!
Sun has written an excellent (but a little too technical) article about the codebase property, and you can find it here:
http://java.sun.com/j2se/1.5.0/docs/guide/rmi/codebase.html

More information about the codebase and the codebase editor can be found here:
http://www.genady.net/rmi/v20/docs/laun ... ebase.html
genady
Site Admin
 
Posts: 396
Joined: Sat Aug 16, 2003 5:15 pm

Return to RMI FAQ

Who is online

Users browsing this forum: No registered users and 0 guests

cron