简体   繁体   English

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

[英]java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: java.lang.ClassNotFoundException: ServicesTableau

I need your help around JAVA RMI, i developped a sample program used to sort table.我需要您在 JAVA RMI 方面的帮助,我开发了一个用于对表进行排序的示例程序。 but i got this exception:但我得到了这个例外:

Erreur RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: ServicesTableau

and this is my Server source code :这是我的服务器源代码:

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);
    }
    */
    }
}

That class isn't available on the CLASSPATH of the RMI Registry.该类在 RMI 注册表的 CLASSPATH 上不可用。 The simplest way to fix it is to start the Registry in the same JVM, via LocateRegistry.createRegistry().修复它的最简单方法是通过LocateRegistry.createRegistry().在同一个 JVM 中启动 Registry LocateRegistry.createRegistry(). Store the result in a static field.将结果存储在静态字段中。

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

I spent a few hours to successfully start the simple example form Orcale!我花了几个小时成功启动了简单的示例表单 Orcale!

Hope could help you希望能帮到你

First, I run the program on Windows首先,我在 Windows 上运行程序

I totally copy the code from here我完全从这里复制代码

but i delete the package and put that three .class file together for the convince但我删除了包并将三个 .class 文件放在一起以说服

and if you are not familar with this i hope you'd better do it, too如果你不熟悉这个,我希望你最好也这样做

because when package get in, the problem will be more complicated因为当包裹进来时,问题会更复杂

There are three steps to do:有三个步骤要做:

1.start rmiregistry 1.启动rmiregistry

start rmiregistry -J-Djava.class.path=./

it is for "remote interface definition"它用于“远程接口定义”

so that the rmiregistry can find the class以便 rmiregistry 可以找到类

then solve the ClassNotFoundException然后解决 ClassNotFoundException

2.run server 2.运行服务器

start java Server

then you can see the output:然后你可以看到输出:

Server ready服务器就绪

3.run client 3.运行客户端

java Client

output:输出:

response: Hello, world!回复:你好,世界!

then talk about how to deal with package然后说说怎么处理包

Usually the Server.class and interface.class---"remote interface definition"通常Server.class和interface.class---“远程接口定义”

should be in the same package应该在同一个包中

and you need to know how to run the .class with package并且您需要知道如何使用包运行 .class

java {packagename}.Server

the classpath default is "./"类路径默认为“./”

and package declare will help to locate the interface.class which is needed for Server.class和包声明将有助于定位 Server.class 所需的 interface.class

so we don't need to separately set -cp所以我们不需要单独设置 -cp

BTW, if you try set the real classpath, you will get error instead顺便说一句,如果您尝试设置真实的类路径,则会出现错误

As for "start rmiregistry"至于“启动rmiregistry”

it has no default classpath它没有默认的类路径

so we need to set it所以我们需要设置它

and it should be the same as the classpath's default value "./"它应该与类路径的默认值“./”相同

The answer was for IDE based project.答案是基于 IDE 的项目。

you need to ' start rmiregistry ' from with in the build folder.您需要从构建文件夹中“启动 rmiregistry ”。

for example: in Intellij例如:在Intellij 中

  1. open terminal inside ' target -> classes ' folder在“目标-> 类”文件夹中打开终端
  2. run 'start rmiregistry'运行“启动 rmiregistry”
  3. then run your server code using intellij然后使用 Intellij 运行您的服务器代码

for eclipse I hope its build folder对于 Eclipse 我希望它的构建文件夹

In some cases, you need to move you rmi clients code (interface and main) to default package.在某些情况下,您需要将 rmi 客户端代码(接口和主)移动到默认包。 Repeate it for server side.在服务器端重复它。 It can solve you problem(work with packaging in rmi is not so obvious).它可以解决您的问题(在 rmi 中使用包装不是那么明显)。

This error is because of not writing security manager code, because of which the class can't get loaded.这个错误是因为没有编写安全管理器代码,因此无法加载类。 So make sure you add code for the security manager.因此,请确保为安全管理器添加代码。
If the compiler doesn't find the security manager then create a new one.Add the code in main method.如果编译器没有找到安全管理器,则创建一个新的。在 main 方法中添加代码。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 weblogic上下文查找错误:java.rmi.UnmarshalException:错误解组参数 - weblogic context lookup error : java.rmi.UnmarshalException: error unmarshalling arguments ResultSet错误java.rmi.UnmarshalException - ResultSet Error java.rmi.UnmarshalException RMI 远程异常:java.lang.ClassNotFoundException - RMI Remote Exception : java.lang.ClassNotFoundException java.rmi.UnmarshalException:java.lang.ClassNotFoundException。 无法使用RMI从另一个物理JVM访问类 - java.rmi.UnmarshalException: java.lang.ClassNotFoundException. Can't get acces to class from another physical JVM using RMI RMI 调用中的 java.rmi.UnmarshalException - java.rmi.UnmarshalException in RMI call javax.ejb.EJBException:嵌套异常是:java.rmi.UnmarshalException:找不到方法:'helloWorld(Ljava.lang.Long; Ljava.util.List;)' - javax.ejb.EJBException: nested exception is: java.rmi.UnmarshalException: Method not found: 'helloWorld(Ljava.lang.Long;Ljava.util.List;)' RMI客户端无法查找服务器-java.rmi.UnmarshalException - RMI client cannot lookup server - java.rmi.UnmarshalException java.lang.ClassNotFoundException异常 - java.lang.ClassNotFoundException exception java.rmi.UnmarshalException:无法通过服务器提取客户端类 - java.rmi.UnmarshalException: unable to pull client classes by server java.lang.ClassNotFoundException错误 - java.lang.ClassNotFoundException error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM