1

I am coding a RMI program with 3 JAR:

  • RMIServer, contains server-side classes
  • RMIClient contains client-side classes
  • RMIResource contains server & client shared content (interfaces, custom exceptions)

To make separate JAR files, I created 3 projects in NetBeans, then I declared the shared Jar in the "Libraries/Build" section of the other 2 projects.

Everything just build-up fine, no error.

But when I try to launch the server through the command-line, which was simple before I had the idea to put the shared files in a distinct JAR, this is suddenly pain in the a**...

Here are a few examples of commands I tried:

  • Keeping the ClassPath pointing to the server resources, but using dual CodeBase

    java -cp ~/NetBeansProjects/RMIServer/dist/RMIServer.jar -Djava.rmi.server.codebase="file:/home/myuser/netbeansprojects/rmiserver/dist/rmiserver.jar file:/home/myuser/netbeansprojects/rmiserver/dist/lib/rmiresource.jar" rmiserver.Shop
    

Result:

Network exception: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: rmiresource.BookingManager
...
  • Using dual ClassPath but keeping the CodeBase pointing to the server resources

    java -cp "~/NetBeansProjects/RMIServer/dist/RMIServer.jar;~/NetBeansProjects/RMIServer/dist/lib/RMIResource.jar" -Djava.rmi.server.codebase=file:/home/myuser/netbeansprojects/rmiserver/dist/rmiserver.jar rmiserver.Shop
    

Result:

Exception in thread "main" java.lang.NoClassDefFoundError: rmiserver/Shop
Caused by: java.lang.ClassNotFoundException: rmiserver.Shop
...
  • Using dual ClassPath & dual CodeBase

    java -cp "~/NetBeansProjects/RMIServer/dist/RMIServer.jar;~/NetBeansProjects/RMIServer/dist/lib/RMIResource.jar" -Djava.rmi.server.codebase="file:/home/myuser/netbeansprojects/rmiserver/dist/rmiserver.jar file:/home/myuser/netbeansprojects/rmiserver/dist/lib/rmiresource.jar" rmiserver.Shop
    

Result:

Exception in thread "main" java.lang.NoClassDefFoundError: rmiserver/Shop
Caused by: java.lang.ClassNotFoundException: rmiserver.Shop
...

EDIT: I am working on the local computer, simulating distant connections. Thus I use 'file' protocol and not 'http'.

Am I missing something? Thanks for any help you would provide


I tested out again my 1st solution since it was the most promising:

    java -cp ~/NetBeansProjects/RMIServer/dist/RMIServer.jar -Djava.rmi.server.codebase="file:/home/myuser/netbeansprojects/rmiserver/dist/rmiserver.jar file:/home/myuser/netbeansprojects/rmiserver/dist/lib/rmiresource.jar" rmiserver.Shop

It still failed.

Then I tested out on Windows:

  1. Setup the rmiregistry with an empty classpath (and cd to the java/bin directory)

    set CLASSPATH=""; export CLASSPATH
    start rmiregistry
    
  2. Launch the server with an equal command as before (moduo the Win env changes)

    java -cp c:/NetBeansProjects/RMIServer/dist/RMIServer.jar -Djava.rmi.server.codebase="file:/c:/netbeansprojects/rmiserver/dist/rmiserver.jar file:/c:/netbeansprojects/rmiserver/dist/lib/rmiresource.jar" rmiserver.Shop
    

And... It worked!

I cleaned-up/rebuilt the solution both on Linux & Windows and it is still not working on Linux and working on Windows... I use the same Netbeans version on both!

Can someone explain that to me? I am using the JDK 6 on Linux & JDK 7 on Windows: would that have an impact?

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Bernard Rosset
  • 4,523
  • 6
  • 27
  • 29

1 Answers1

0

A file: codebase can't work out of the local machine. You need to use HTTP. You could possibly use a file: URL pointing to a shared directory, such that the URL makes sense at a client, but this won't work outside the LAN.

Unless you are using the codebase feature, the RMI Registry needs access to the shared classes via its classpath: rmiregistry -J-Dclasspath=... It's simpler to use LocateRegistry.createRegistry(), then it's in the same JVM as your remote objects and uses the same classpath of course.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • I omitted to expalin I was working on the local computer, thus RMI is only simulating distant connections. I'll try to change the rmiregistry classpath. – Bernard Rosset Sep 02 '11 at 18:15