0

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;
}
Tina J
  • 4,983
  • 13
  • 59
  • 125
  • 1
    can you replace your code with this public HelloServer()throws RemoteException {} – Vishal Gajera Nov 23 '15 at 07:12
  • It fixed it! How come it was running the other time? It was the same code I believe! – Tina J Nov 23 '15 at 07:15
  • 1
    @vishalgajera There's no reason why that would fix the problem. Unless the remote object class extends `UnicastRemoteObject` or `Activatable` its constructor doesn't need to throw `RemoteException.` OP must have improved his deployment, or else he wasn't running the code he thought he was running. – user207421 Nov 23 '15 at 08:54
  • Again, I run into the same problem. Same exception again... – Tina J Nov 23 '15 at 20:16
  • 1
    Have you looked at the [duplicate](http://stackoverflow.com/questions/464687/running-rmi-server-classnotfound)? Have you figured out what you changed between 'it fixed it!' and 'I run into the same problem'? – user207421 Nov 24 '15 at 01:52
  • Yes, thanks. That was almost related. I should have run registry in the `bin` folder. – Tina J Nov 24 '15 at 17:33

0 Answers0