java.rmi.ServerException:服务器线程中发生RemoteException(ClassNotFoundException)

java.rmi.ServerException:服务器线程中发生RemoteException(ClassNotFoundException),java,exception,rmi,Java,Exception,Rmi,以下方法: 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) { JOpti

以下方法:

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中的消息会告诉我启动服务器时出现问题,然后是上述异常。这可能是什么原因


我不明白,当我导入了正确的包时,为什么最后一个异常语句说class not found exc有四个异常情况

  • 导出时:您没有运行“rmic”,也没有按照Javadoc中针对
    UnicastRemoteObject
    的前言中描述的步骤使其变得不必要

  • 绑定时:注册表没有存根、远程接口或依赖于其类路径的东西

  • 查找时:客户端的类路径上没有这些东西

  • 调用远程方法时:向类路径上不存在的类的服务器发送某些内容,或从服务器接收某些内容(包括异常)不在类路径上的类:在这两种情况下,都可能是远程接口的方法签名中提到的类或接口的派生类或接口实现

  • 这是案例2。注册表找不到指定的类

    有几种解决方案:

  • 使用包含相关JAR或目录的类路径启动注册表

  • 通过
    LocateRegistry.createRegistry()在服务器JVM中启动注册表。

  • 使用动态存根,如
    UnicastRemoteObject的Javadoc序言中所述。
    但是,您可能仍然会遇到远程接口本身或它所依赖的类的相同问题,在这种情况下,上述1-3仍然适用于该类

  • 确保上述情况(4)不会发生

  • 使用代码库特性。这实际上是一个部署选项,在初始开发阶段需要避免

  • 要解决此错误非常简单,请执行以下步骤:

      例如,您的java文件考虑d驱动器< /LI>
    • 启动RMID注册表驱动器(示例D:\Start rmiregistry),然后不要在其他驱动器上启动RMI注册表,这将产生上述错误

    (无论文件位于何处,请启动
    rmiregistry

    您可以从任何位置启动rmiregistry,但必须确保编译的类已经在类路径中。例如:-

    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
    
    E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>set classpath=%classpath%;E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes
    E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes>c:
    C:\>注册中心
    
    上述措施应该可以很好地发挥作用

    通常,如果从编译类的根位置启动rmiregistry(上面的示例是E:\ARMSRemoteUpdater\WebContent\WEB-INF\classes),这将起作用,因为。(点-当前目录)已在类路径中设置

    但一旦你离开。(点-当前目录)从类路径,上述工作条件也将失败


    希望我已经详细解释过了。

    我遇到了同样的问题,不同的解决方案对我有效。我运行了两个不同的IntelliJ项目,每个项目中都有一个接口副本。其中一个在包中,另一个不在包中,这就是导致此错误的原因

    解决方案:

    • 确保接口副本不在包中
    • 确保接口副本具有完全相同的包名

    我将尽可能更好地解释我所做的: 第一。我声明了classpath变量,如下所示:

  • 设置类路径=%classpath%
  • set classpath=C:\compiler
  • set classpath=C:\compiler\libro\cap07\rmi\hello\hello.java
  • set classpath=C:\compiler\libro\cap07\rmi\hello\Server.java
  • set classpath=C:\compiler\libro\cap07\rmi\hello\Client.java
    • (多功能一体式线集:
    set classpath=%classpath%;C:\compiler;C:\compiler\libro\cap07\rmi\hello\hello.java;C:\compiler\libro\cap07\rmi\hello\Server.java;C:\compiler\libro\cap07\rmi\hello\Client.java)

    • (我不确定.java文件是否正确,但我也写了它们以表示怀疑)
    第二。我使用行
    javac-dc:\compiler Hello.java Server.java Client.java
    进行编译。其中
    C:\compiler
    是Eclipse IDE上类似src的根目录

    三,。我运行了
    启动注册表
    行。(不管你在哪里运行,都是一样的)

    第四。我跑:

    start java-classpath C:\compiler-Djava.rmi.server.codebase=文件:C:\compiler/libro.cap07.rmi.hello.server

    您已经知道
    C:\compiler
    ,但是您需要在最后一个位置定义包地址,以便命令可以找到.class文件。打开任何.java文件并复制不带packages sentense的包地址。当您打开src目录(在我的例子中是C:\compiler)时,您将看到创建的所有目录序列。正确创建此命令行后,无论在何处运行它,C:,D:,src,以及它将在何处运行

    五号。最后,我使用以下命令运行客户端类:

    java-classpath C:\compiler libro.cap07.rmi.hello.Client

    总之,如果classpath变量没有创建,或者创建错误,或者第四点的语句没有得到很好的处理,JVM就会抛出相同或类似的错误。在那里搜索


    (对不起,我的英语。)

    @SuhailGupta参见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