ClassNotFoundException in Client when trying to access stub on a different server (Java RMI)
Hello Experts,
I have my server class running on another server. My client is trying to access the remote object and it is throwing the follwoing error:
error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: JoptServer_Stub
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: JoptServer_Stub
The stub named JoptServer_Stub is available on the server. I am able to successfully bind the remote object to the RMI Engine. I am also attaching the files for your reference.
Are you getting this exception on the server's console or client's console?
anilallewar
The stub for the remote RMI server generated through rmic tool has to be available on the client classpath for the RMI invocation to work. The way the RMI communication passes is
Thanks for providing the solutions. I generated the stub on the client and it worked. But I will try the solution provided by anilallewar and will post the results here.
One question to anilallewar - Do you mean to say that the server class should not have a main method?
anilallewar
Nope..the server class needs to have the main method for Java to call.However since your main method instantiates the registry and completes, it will take the registry down with it when it completes.
Now when the client makes RMI call, the registry is down and the stub can't be retrieved. It mightbe the case that the registry is still running if it was launched as a daemon; however the server stub registered with the server is removed since the server class itself is finished executing.
Hence you need to keep the server class running infinitely by adding the code I provided.
ajaycv
ASKER
I am getting a Class Cast Exception from the stub. Can you please help?