Java.rmi.ServerException: Remote exception occurred in server thread (ClassNotFoundException)

Next 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 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 by a message in JOptionPane, which talks about the problem with starting the server, and then the above exception. What could be the reason for this?

I don’t understand why the last exception statement says that the class was not found exc when I imported the correct packages

+6
source share
3 answers

There are three cases of this exception.

  • On export: you did not run 'rmic', and you did not follow the steps described in the Javadoc preamble for UnicastRemoteObject to make this unnecessary.

  • When binding: the registry does not have a stub or a remote interface or anything on which they depend on its class path.

  • when searching: the client does not have these things in its path to the classes.

This is case 2. The registry cannot find the named class.

There are four solutions:

  • Run the registry using CLASSPATH, which includes the appropriate JARs or directories.

  • Run the registry on your JVM server through LocateRegistry.createRegistry().

  • Use dynamic stubs as described in the Javadoc UnicastRemoteObject. . However, you can still encounter the same problem with the remote interface itself or the class on which it depends, in which case the 1–3 above still apply to this class / these classes.

  • Use the codebase function. This is truly a deployment option and IMO, which should be avoided during the initial development phase.

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

An error that is very easy to solve, follow these steps:

  • For example, your Java file considers a D-disk
  • Run rmiregistry D drive (example D: \ start rmiregistry), then do not run rmiregistry on other drives, this will result in the above error.

(Wherever your file is located, run rmiregistry )

+3
source

You can run rmiregistry from anywhere, but you must make sure that the compiled classes are already in your class path. For instance: -

 E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>set classpath=%classpath%;E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes <ENTER> E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>c: <ENTER> C:\>rmiregistry 

And above should work fine.

In general, if you run rmiregistry from the root location of the compiled classes (the above example is E: \ ARMSRemoteUpdater \ WebContent \ WEB-INF \ classes), this will work, because. (dot-current directory) is already installed in your classpath.

But as soon as you delete. (dot-current directory) from your class path, the above working condition will also fail.

Hope I explained in detail.

-1
source

Source: https://habr.com/ru/post/909809/


All Articles