java.rmi.ServerException: RemoteException occurred in server thread (ClassNotFoundException)

59,120

Solution 1

There are four cases of this exception.

  1. When exporting: you didn't run 'rmic' and you didn't take the steps described in the preamble to the Javadoc for UnicastRemoteObject to make it unnecessary.

  2. When binding: the Registry doesn't have the stub or the remote interface or something they depend on on its classpath.

  3. when looking up: the client does't have these things on its classpath.

  4. When calling a remote method: you either sent something to the server of a class not present on its CLASSPATH, or received something from the server (including an exception) of a class not on your CLASSPATH: in both cases possibly a derived class or interface implementation of a class or interface mentioned in the remote interface's method signature.

This is case 2. The Registry can't find the named class.

There are several solutions:

  1. Start the Registry with a CLASSPATH that includes the relevant JARs or directories.

  2. Start the Registry in your server JVM, via LocateRegistry.createRegistry().

  3. Use dynamic stubs, as described in the preamble to the Javadoc of UnicastRemoteObject. However you may then still run into the same problem with the remote interface itself or a class that it depends on, in which case 1-3 above still apply to that class/those classes.

  4. Ensure that case (4) above doesn't occur.

  5. Use the codebase feature. This is really a deployment option and IMO something to be avoided at the initial development stage.

Solution 2

Remote Server Error:RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: mathInterface

The error very simple to solve to be perform following steps:

  • For example your java file consider D drive
  • Start rmiregistry D drive( example D:\start rmiregistry)then don't start rmiregistry on the other drives, it will yield the above error

(Wherever your file is, start rmiregistry)

Solution 3

I will try to explain it as better as possible what I did: 1st. I declared the classpath variable like follow:

  1. set classpath=%classpath%
  2. set classpath=C:\compiler
  3. set classpath=C:\compiler\libro\cap07\rmi\hello\Hello.java
  4. set classpath=C:\compiler\libro\cap07\rmi\hello\Server.java
  5. set classpath=C:\compiler\libro\cap07\rmi\hello\Client.java
  • (All in one lineset:

set classpath=%classpath%;C:\compiler;C:\compiler\libro\cap07\rmi\hello\Hello.java;C:\compiler\libro\cap07\rmi\hello\Server.java;C:\compiler\libro\cap07\rmi\hello\Client.java)

  • (I'm not sure if the .java files were nesesary, but I also wrote them for doubts).

2nd. I compilered with the line javac -d C:\compiler Hello.java Server.java Client.java. Where C:\compiler is the root directory like src on Eclipse IDE.

3rd. I ran the start rmiregistry line. (and don´t matter where you run it, it's the same).

4th. I ran:

start java -classpath C:\compiler -Djava.rmi.server.codebase=file:C:\compiler/ libro.cap07.rmi.hello.Server

You already know C:\compiler, but you need define packages address on the last to that the command can find the .class files. Open any .java file and copy the package address without packages sentense. You will see when you open the src directory (in my case C:\compiler), you find all directory sequence created. When this command line is created correctly, no matter where you will run it, C:, D:, src, anywhere it wil run.

5th. And finally, I ran the Client class with:

java -classpath C:\compiler libro.cap07.rmi.hello.Client

In conclusion, if the classpath variable won't created or it's to created wrong or the sentence of 4th point is not addressed well the JVM throws the same or similar error. Search there!

(Sorry my english).

Share:
59,120
Suhail Gupta
Author by

Suhail Gupta

"There's nothing more permanent than a temporary hack." - Kyle Simpson "The strength of JavaScript is that you can do anything. The weakness is that you will." - Reg Braithwaite I am on internet Twitter @suhail3 E-mail [email protected]

Updated on July 06, 2022

Comments

  • Suhail Gupta
    Suhail Gupta almost 2 years

    The following method :

    private void startServer() { // snippet that starts the server on the local machine
        try {
             RemoteMethodImpl impl = new RemoteMethodImpl();
             Naming.rebind( "Illusive-Server" , impl );
        }catch(Exception exc) {
            JOptionPane.showMessageDialog(this, "Problem starting the server", "Error", JOptionPane.ERROR_MESSAGE);
            System.out.println(exc);
        }
    }
    

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

    When i start my project, i am greeted with the message in JOptionPane saying problem starting the server and then the above exception. What could be the reason for this ?

    I don't understand why does the last statement of exception says class not found exc when i have imported the right packages