java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: Interface


java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: Interface


While running any RMI applications we need to have rmiregistry running.
This registry should be up and running before starting the server application.

The problem is RMI Registry can't find the stub class. It does not know from where to load the classes. 

The solution is to make the class files of the java application available to the classpath of the rmiregistry

Below are some possible solutions to make the file available to rmiregistry:

1. Start the RMI Registry from the Windows command prompt in the CLASSPATH(that is set in the environment variable from where we execute java or javac) that includes the relevant JARs or directories.

Suppose the java is in D:/java then start the rmiregistry from D:/java

Run the below command from  /bin, /build, or /build/classes folder, whichever folder is the root of your built files.

>> rmiregisrty

or

>>start rmiregistry

2. Or Start the RMI Registry in the server JVM from java using LocateRegistry.createRegistry() and store it in the static field.

3. Or Can use the codebase feature.
It will add the required files will be added in the path and will be available.

Can set java.rmi.server.codebase property in the vm arguments as shown below

-Djava.rmi.server.codebase=file:${workspace}/project/bin

If setting java.rmi.server.codebase property from java file then makes sure that it is set before exporting any remote object.
e.g.
System.setProperty("java.rmi.server.codebase", clazz.getProtectionDomain().getCodeSource().getLocation().toString());

4. (If using Java 7)Go to the location where your project class files are located(up till bin) and start the registry using the below command:

rmiregistry -J-Djava.rmi.server.useCodebaseOnly=false

Comments

Popular Posts