java.rmi.UnmarshalException: error unmarshalling return; nested exception is

RMI调用

在server端通过RMI来发布服务的时候,远程调用的时候可能会出现一下错误:

Exception in thread “main” java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: rmi.IHelloService (no security manager: RMI class loader disabled)
at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:127)
at java.rmi.Naming.lookup(Naming.java:101)
at rmitest.RemoteClient.main(RemoteClient.java:22)
Caused by: java.lang.ClassNotFoundException: rmi.IHelloService (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:556)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:646)
at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:311)
at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:265)
at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1798)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1746)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2040)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1571)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:431)
at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:123)
… 2 more

当在本地用同样的方法进行调用的时候,就不会报错,调用就会成功!!远程调用就不好使,到最后才发现原因,

不只是接口服务于实现类是一样的, 并且包的名字也必须一样才可以!!!!

不然的话,在调用的时候就会发生以上的错误~~~··

所以针对以上的情况,可以把这些类封装成一个公共的jar包来引用,才能很好的避免调用的时候出现错误。

你可能感兴趣的:(JAVA,RMI)