java.rmi.ServerException: RemoteException occurred in server thread (ClassNotFoundException)(java.rmi.ServerException:远程异常发生在服务器线程(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 ?
我不明白为什么最后一条异常声明说当我导入了正确的包时,class not found exc
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.
查找时:客户端的类路径中没有这些东西.
when looking up: the client does't have these things on its classpath.
调用远程方法时:您要么向其 CLASSPATH 上不存在的类的服务器发送了一些东西,要么从不在您的 CLASSPATH 上的类的服务器接收到一些东西(包括异常):在这两种情况下可能是远程接口的方法签名中提到的类或接口的派生类或接口实现.
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.
这是案例 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.
确保上述情况 (4) 不会发生.
Ensure that case (4) above doesn't occur.
使用代码库功能.这确实是一个部署选项,而 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:远程异常发生在服务器线程(ClassNotFoundException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:java.rmi.ServerException:远程异常发生在服务器线程
基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 降序排序:Java Map 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01