简体   繁体   English

在Windows 7上使用RMI

[英]Using RMI on the windows 7

I am a new with using RMI on windows 7, and I want to run my project with RMI to show "HelloWorld", but I could not run it, because I have got the following error. 我是在Windows 7上使用RMI的新手,并且我想使用RMI运行我的项目以显示“ HelloWorld”,但是我无法运行它,因为出现了以下错误。 anyone can help me please. 任何人都可以帮助我。 also I have used JDK 1.6. 我也用过JDK 1.6。

My error is: 我的错误是:

java.rmi.UnmarshalException: error unmarshalling arguments; java.rmi.UnmarshalException:错误解组参数; nested exception is: 嵌套的异常是:

    java.lang.ClassNotFoundException: Hello_Stub

There are three ways you can get this exception: 有三种方法可以获取此异常:

  1. When constructing/exporting your remote object. 构造/导出远程对象时。 In this case it means you haven't supplied a port number parameter to super(int port...) if your remote object extends UnicastRemoteObject, or to UnicastRemoteObject.exportObject() otherwise, and you haven't generated a stub via rmic . 在这种情况下,它意味着你没有提供的端口号参数super(int port...)如果你的远程对象扩展UnicastRemoteObject,UnicastRemoteObject.exportObject()否则你有没有产生经由支rmic Note that if you supply a port number parameter, even zero, you don't need to run rmic at all. 请注意,如果您提供的端口号参数,甚至为零,则根本不需要运行rmic

  2. When binding/rebinding the remote object to the Registry (in the server). 将远程对象绑定/重新绑定到注册表时(在服务器中)。 In this case it means you haven't supplied a port number etc as above, but you have generated the stub, otherwise you wouldn't get this far because of (1), but the _Stub class isn't available to the Registry on its CLASSPATH. 在这种情况下,这意味着您没有提供上面的端口号等,但是您已经生成了存根,否则由于(1)的原因您不会得到这么多, 但是 _Stub类在注册表上不可用其CLASSPATH。 The simplest solution to this is to run the Registry in the same JVM, via LocateRegistry.createRegistry() . 最简单的解决方案是通过LocateRegistry.createRegistry()在同一个JVM中运行注册表。 Note that the return value of this method needs to be stored somewhere where it won't be garbage-collected, eg in a static variable. 请注意,此方法的返回值需要存储在不会进行垃圾回收的位置,例如,在静态变量中。

  3. When looking up the Registry (in the client). 查找注册表时(在客户端中)。 In this case it means you haven't supplied a port number etc as above, but you have generated the stub, otherwise you wouldn't get this far because of (1) and (2), but the _Stub class isn't available to the client on its CLASSPATH. 在这种情况下,这意味着您没有提供上面的端口号等,但是您已经生成了存根,否则由于(1)和(2)的缘故,您不会走得太远, 但是 _Stub类不可用在其CLASSPATH上传递给客户端。 Solution: deploy it to the client. 解决方案:将其部署到客户端。

I guess you have to use the rmic.exe to generate your remote classes stubs. 我想您必须使用rmic.exe生成远程类存根。 These are not automatically generated by your Java compiler (javac.exe). 这些不会由Java编译器(javac.exe)自动生成。

You can define an Ant Task (called rmic) to simplify your life and make sure your stubs are automatically generated. 您可以定义一个Ant Task (称为rmic)来简化您的生活,并确保自动生成存根。

If you are using Eclipse you can even include this task as part of your building process so that you can be sure they are generated every time your code is compiled. 如果您使用的是Eclipse,则甚至可以将此任务包含在构建过​​程中,以确保每次编译代码时都会生成该任务。 Most probably other IDEs offer similar features. 可能其他IDE也提供类似的功能。

It sounds like maybe you're perhaps following an outdated version of this tutorial: http://docs.oracle.com/javase/1.5.0/docs/guide/rmi/hello/hello-world.html . 听起来您可能正在遵循本教程的过时版本: http : //docs.oracle.com/javase/1.5.0/docs/guide/rmi/hello/hello-world.html If that's not the case, check your Java version on the command line ( java -version ). 如果不是这种情况,请在命令行上检查您的Java版本( java -version )。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM