在学习RMI的时候,首先启动了服务端,然后再启动客户端,在启用客户端的时候报错,如下:
Exception in thread "main" java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: com.RMIServerDemo01.IRemoteObj (no security manager: RMI class loader disabled)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at com.RMIClientDemo01.RMIClient.main(RMIClient.java:11)
Caused by: java.lang.ClassNotFoundException: com.RMIServerDemo01.IRemoteObj (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:255)
at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1559)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1515)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
... 2 more
经过查询,主要有两个原因,如下是处理过程:
1、客户端及服务端的接口要手工抛出异常:RemoteException,如下:
2、客户端与服务端的包结构要保持一致
这是报错的:
这是调整后正常的:
经过以上两步就解决了,记录一下。