java.rmi.ServerException:服务器线程中发生RemoteException(ClassNotFoundException) [英] java.rmi.ServerException: RemoteException occurred in server thread (ClassNotFoundException)
问题描述
以下方法:
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);
}
}
抛出此异常: java .rmi.ServerException:服务器线程中发生RemoteException;嵌套异常是:
java.rmi.UnmarshalException:错误解组参数;嵌套异常是:
java.lang.ClassNotFoundException:Interfaces.RemoteMethodIntf
当我开始我的项目时,我我收到了JOptionPane中的消息,说问题启动服务器,然后是上述异常。这可能是什么原因?
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
推荐答案
这种情况有三种情况。
-
导出时:你没有运行'rmic'而你没有采用Javadoc序言中描述的步骤
UnicastRemoteObject
使其不必要。
绑定时:注册表没有存根或远程接口或它们依赖于其类路径的东西。
When binding: the Registry doesn't have the stub or the remote interface or something they depend on on its classpath.
查找时:客户端执行在类路径上有这些东西/ p>
when looking up: the client does't have these things on its classpath.
这是案例2.注册表找不到指定的类。
This is case 2. The Registry can't find the named class.
有四种解决方案:
-
使用包含相关JAR或目录的CLASSPATH启动注册表。
Start the Registry with a CLASSPATH that includes the relevant JARs or directories.
通过 LocateRegistry.createRegistry()启动服务器JVM中的注册表。
使用动态存根,如 UnicastRemoteObject的Javadoc前言中所述。
然而,您可能仍会遇到远程接口本身或它依赖的类也存在同样的问题,在这种情况下,上面的1-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.
使用代码库功能。这实际上是一个部署选项,IMO在初始开发阶段应该避免。
Use the codebase feature. This is really a deployment option and IMO something to be avoided at the initial development stage.
这篇关于java.rmi.ServerException:服务器线程中发生RemoteException(ClassNotFoundException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!