Link to home
Start Free TrialLog in
Avatar of ajaycv
ajaycv

asked on

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.

Please let me know the solution to this problem.

P.S: My client and server are not on the same machine.
Client.java
JoptRemoteCalls.java
JoptServer.java
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Are you getting this exception on the server's console or client's console?
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

Client<--->stub<--->[NETWORK]<--->skeleton<--->Server

So either create a jar of the stub classes generated through rmic or place the classes directly in the client classpath.
ASKER CERTIFIED SOLUTION
Avatar of anilallewar
anilallewar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ajaycv
ajaycv

ASKER

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?
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.
Avatar of ajaycv

ASKER

I am getting a Class Cast Exception from the stub. Can you please help?
Avatar of ajaycv

ASKER

Fixed it. The solution is that the server stub should be in the same package as on the client or vice versa.
Glad if I could be of help in fixing your prob!!
Avatar of ajaycv

ASKER

The tips were helpful