RMI Server Exception

江枫思渺然 提交于 2019-12-01 06:25:14

问题


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

My registry cod for the main method in Server2 class is

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

192.168.1.4 is another machine in the same LAN.

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$1.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$1.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.

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


回答1:


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.




回答2:


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

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.

Also check similar question running rmi server, classnotfound




回答3:


java.lang.ClassNotFoundException: example.Hello.RemoteHello2

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




回答4:


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.



来源:https://stackoverflow.com/questions/3629568/rmi-server-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!