I'm new to RMI, and was following the Oracle's RMI tutorial code at here and wrote something similar.
My code was working correctly, everything fine. But I didn't touch the code, and today after 3 weeks when I just came and tried to run it again , surprisingly it was not running anymore, and throws the following exception: (of course I did start rmiregistry
).
How can I fix the problem? I am running Java 1.8.0.60 and use eclipse.
SOLUTION: I should have run rmiregistry
in the bin
folder (or probably set classpath with other ways).
Server exception: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: test.Hello
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: test.Hello
... continued ...
Here is the code for HelloServer
:
package test;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class HelloServer implements Hello {
public HelloServer() {}
public String pollServer() {
String data= EchoServerRMI.queuePoll();
System.out.println("polling test"+data);
return data;
// return "1";
}
public static void main(String args[]) {
try {
HelloServer obj = new HelloServer();
Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry();
registry.bind("Hello", stub);
System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}
And here is the code for Hello
class:
package test;
import java.rmi.*;
public interface Hello extends Remote {
String pollServer() throws RemoteException;
}