Java RMI 服务器异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3629568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 02:55:38  来源:igfitidea点击:

RMI Server Exception

javarmi

提问by Shew

I am getting below exception from RMI when I try to run a Server which uses a remote registry.

当我尝试运行使用远程注册表的服务器时,我遇到了来自 RMI 的异常。

My registry cod for the main method in Server2 class is

我在 Server2 类中的主要方法的注册表代码是

Registry registry = LocateRegistry.getRegistry("192.168.1.4",1100);
registry.rebind("Hello",stub);

192.168.1.4 is another machine in the same LAN.

192.168.1.4 是同一局域网中的另一台机器。

Please help me.

请帮我。

Server2 exception:java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
 java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
 java.lang.ClassNotFoundException: example.Hello.RemoteHello2
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
 java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
 java.lang.ClassNotFoundException: example.Hello.RemoteHello2
 at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:396)
 at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
 at sun.rmi.transport.Transport.run(Transport.java:159)
 at java.security.AccessController.doPrivileged(Native Method)
 at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
 at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
 at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
 at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
 at java.lang.Thread.run(Thread.java:619)
 at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
 at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
 at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377)
 at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
 at example.Hello.Server2.main(Server2.java:29)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
 java.lang.ClassNotFoundException: example.Hello.RemoteHello2
 at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
 at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386)
 at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
 at sun.rmi.transport.Transport.run(Transport.java:159)
 at java.security.AccessController.doPrivileged(Native Method)
 at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
 at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
 at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
 at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
 at java.lang.Thread.run(Thread.java:619)

I have the class called RemoteHello2 and I can confirm this because another Server program in the same package is running fine.

我有一个名为 RemoteHello2 的类,我可以确认这一点,因为同一个包中的另一个服务器程序运行良好。

I have 2 server programs, 1 uses localhost as the registry and 2nd one uses a remote server as registry.

我有 2 个服务器程序,1 个使用 localhost 作为注册表,第二个使用远程服务器作为注册表。

回答by John Gardner

java.lang.ClassNotFoundException: example.Hello.RemoteHello2

java.lang.ClassNotFoundException:example.Hello.RemoteHello2

So it looks like you're missing that class from the classpath on the server?

所以看起来您在服务器上的类路径中缺少该类?

回答by YoK

Here are troubleshooting tips from RMI guide: Try it!! This should help

以下是来自 RMI 指南的故障排除提示:试试吧!!这应该有帮助

6.1 If you encounter a problem running your RMI server

The first problem you might encounter is the receipt of a ClassNotFoundException when attempting to bind or rebind a remote object to a name in the registry. This exception is usually due to a malformed codebase property, resulting in the registry not being able to locate the remote object's stubs or other classes needed by the stub.

It is important to note that the remote object's stub implements all the same interfaces as the remote object itself, so those interfaces, as well as any other custom classes declared as method parameters or return values, must also be available for download from the specified codebase.

Most frequently, this exception is thrown as a result of omitting the trailing slash from the URL value of the property. Other reasons would include: the value of the property is not a URL; the path to the classes specified in the URL is incorrect or misspelled; the stub class or any other necessary classes are not all available from the specified URL.

6.1 如果在运行 RMI 服务器时遇到问题

您可能遇到的第一个问题是在尝试将远程对象绑定或重新绑定到注册表中的名称时收到 ClassNotFoundException。此异常通常是由于格式错误的代码库属性导致注册表无法定位远程对象的存根或存根所需的其他类。

需要注意的是,远程对象的存根实现了与远程对象本身相同的所有接口,因此这些接口以及声明为方法参数或返回值的任何其他自定义类也必须可从指定的代码库下载.

常见的是,此异常是由于从属性的 URL 值中省略了尾部斜杠而引发的。其他原因包括:属性的值不是 URL;URL 中指定的类的路径不正确或拼写错误;存根类或任何其他必要的类并非都可从指定的 URL 获得

Also check similar question running rmi server, classnotfound

还要检查运行 rmi 服务器的类似问题,classnotfound

回答by mwhidden

If an instance local to the registry works, but not one that is remote, then I would guess is that your java.server.codebase either uses a file: URL, which would not be accessible to a remote registry, or the the remote registry lacks access to the http: or ftp: codebase.

如果注册表本地的实例有效,但不是远程的,那么我猜是您的 java.server.codebase 要么使用文件:URL,远程注册表无法访问该文件,要么使用远程注册表无法访问 http: 或 ftp: 代码库。

回答by cianBuckley

I had this problem. It turns out that I had started the rmi registry through command prompt like normal, however I didn't start it in the same folder as my server.class. When I changed the directory to where server.class was, it worked with no problems.

我有这个问题。事实证明,我已经像往常一样通过命令提示符启动了 rmi 注册表,但是我没有在与 server.class 相同的文件夹中启动它。当我将目录更改为 server.class 所在的位置时,它没有问题。