java.rmi.ServerException:远程异常发生在服务器线程(ClassNotFoundException) [英] java.rmi.ServerException: RemoteException occurred in server thread (ClassNotFoundException)

查看:46
本文介绍了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

推荐答案

这个异常有四种情况.

  1. 导出时:您没有运行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.

有几种解决方案:

  1. 使用包含相关 JAR 或目录的 CLASSPATH 启动注册表.

  1. 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆