RMI初体验--第一次错处理java.rmi.UnmarshalException&ClassNotFoundException

今天参考了一下网上Rhello示例,搞了一下RMI测试。

server端是 java8 

client 段是java6

然后 运行报错:

java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: com.sap.oms.api_order.api_invoice.rmi1.IQrCodeScanner (no security manager: RMI class loader disabled)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at com.test.rmi.QrCodeScannerClient.main(QrCodeScannerClient.java:22)
Caused by: java.lang.ClassNotFoundException: com.test.rmi1.IQrCodeScanner (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadProxyClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveProxyClass(Unknown Source)
at java.io.ObjectInputStream.readProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
... 3 more

刚开始没有仔细查看报错,上网查了一阵,美搞后,后来发现,原来是客户端的rmi接口所在包名不对。

原来: RMI 有要求, 客户端和服务端使用的服务接口类, 包名必须一样。

再返回报错信息仔细看,客户端报错信息里面提示没有找到的类名,里面有包名全路径, 是服务端的包名字符串。大意了。 

相关文章
相关标签/搜索