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

a 夏天 提交于 2019-11-26 00:29:19

问题


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


回答1:


There are three 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.

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

There are four 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. Use the codebase feature. This is really a deployment option and IMO something to be avoided at the initial development stage.




回答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)




回答3:


You can launch rmiregistry from anywhere but you have to make sure that the compiled classes are already in your classpath. For example:-

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 the above should work fine.

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

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

Hope I have explained in details.




回答4:


I got this same issue, and a different solution worked for me. I was running two different IntelliJ projects, with a copy of the interface in each project. One of them was in a package, and the other one wasn't, and that was what was causing this error.

Solutions:

  • Make sure the interface copies aren't in a package.
  • Make sure the interface copies have the exact same package name.


来源:https://stackoverflow.com/questions/9531158/java-rmi-serverexception-remoteexception-occurred-in-server-thread-classnotfou

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!