java.rmi.UnmarshalException:错误解组参数;嵌套异常为:java.lang.ClassNotFoundException:ServicesTableau

java.rmi.UnmarshalException:错误解组参数;嵌套异常为:java.lang.ClassNotFoundException:ServicesTableau,java,rmi,Java,Rmi,我需要你们对JavaRMI的帮助,我开发了一个用于排序表的示例程序。但我有一个例外: Erreur RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: ServicesTabl

我需要你们对JavaRMI的帮助,我开发了一个用于排序表的示例程序。但我有一个例外:

Erreur RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: ServicesTableau
这是我的服务器源代码:

public class Serveur {
    public static void main(String args[]) {

        try {

            System.out.println("Server start ...");
            ServicesTableauImpl od = new ServicesTableauImpl();
            String url = "rmi://" + args[0] + "/ServicesTableauImpl";
            System.out.println("Passe");
            Naming.rebind(url, od);
            System.out.println("Attente d'invocations de client / CTRL-C pour stopper");
        } catch (Exception e) {
            System.out.println("Erreur " + e.getMessage());
        }
    /*
    catch(java.net.MalformatedURLException e){
    System.out.println("Mauvais nom de serveur");
    System.exit(1);
    }
    catch(RemoteException e){
    System.out.println("Pas de Rmiregistry");
    System.exit(1);
    }
    */
    }
}

该类在RMI注册表的类路径上不可用。修复它的最简单方法是在同一JVM中启动注册表,通过
LocateRegistry.createRegistry()。
将结果存储在静态字段中。

此错误是因为未编写安全管理器代码,因此类无法加载。 因此,请确保为安全管理器添加代码。
如果编译器找不到安全管理器,则创建一个新的安全管理器。在main方法中添加代码

if (System.getSecurityManager() == null) then
    System.setSecurityManager(new RMISecurityManager())

在某些情况下,您需要将rmi客户机代码(接口和主)移动到默认包。在服务器端重复。它可以解决您的问题(在rmi中使用打包不是很明显)。

这发生在我身上,因为我没有在与服务器相同的目录中运行
rmiregistry

我花了几个小时成功地启动了简单的示例表单Orcale

希望能帮助你

首先,我在Windows上运行该程序

我完全是从你那里复制代码的

但是我删除了这个包,并将三个.class文件放在一起以供将来使用

如果你不熟悉这一点,我希望你最好也这样做

因为当包裹进入时,问题会更复杂

有三个步骤可以完成:

1.启动注册表

start rmiregistry -J-Djava.class.path=./
用于“远程接口定义”

以便注册中心可以找到该类

然后解决ClassNotFoundException

2.运行服务器

start java Server
然后您可以看到输出:

服务器就绪

3.运行客户端

java Client
输出:

回答:你好,世界

然后谈谈如何处理包裹

java {packagename}.Server
通常是Server.class和interface.class--“远程接口定义”

应该在同一个包中

您需要知道如何使用包运行.class

java {packagename}.Server
类路径默认值为“/”

包declare将帮助定位Server.class所需的interface.class

所以我们不需要单独设置-cp

顺便说一句,如果您尝试设置真实的类路径,您将得到错误

至于“启动注册表”

它没有默认的类路径

所以我们需要设置它


它应该与类路径的默认值相同。“/”

答案是基于IDE的项目

您需要从build文件夹中的启动rmiregistry

例如: 在Intellij中

  • 打开“目标->类别”文件夹内的终端
  • 运行“启动注册表”
  • 然后使用intellij运行服务器代码

  • 对于eclipse,我希望它的构建文件夹

    这个类ServicesTableauImpl在类路径中可用吗?@PradeepSimha缺少的类是
    ServicesTableau
    ,而不是
    ServicesTableauImpl
    。阅读例外。我在Linux下工作,感谢你的回复(我用过它,现在它工作得很好)Linux对答案没有任何影响。不,没有。这是因为找不到该类。您需要读取整个异常。如果他使用的是RMI代码库特性,这只会是由于缺乏安全管理器造成的,而RMI代码库特性没有说明。使用默认包甚至在Java 1.4之后都无法正常工作。您当然必须在客户机和服务器上使用相同的包,即严格地说是相同的类,但它不应该是默认包。您的意思是说“这个答案适用于基于IDE的项目吗?”;如果不是,你指的是哪一个答案?