我目前正在另一个帖子here is the link上关注RMI的小教程! 我遇到的问题是,如果我将所有类放在同一个项目上(我使用Netbeans)那么它可以完美地工作,但在现实生活中,客户端和服务器通常是不同的机器,所以当我尝试将客户端放在不同的项目上并实现相同的接口和SomeStruct类,然后我收到以下错误:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: rmiserver.SomeInterface (no security manager: RMI class loader disabled)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:101)
at clientrmi.SomeClient.main(SomeClient.java:17)
Caused by: java.lang.ClassNotFoundException: rmiserver.SomeInterface (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)
... 3 more
如果我在客户端上实现以下代码:
if(System.getSecurityManager() == null) {
System.setSecurityManager(new SecurityManager());
}
然后我收到以下错误:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1234" "connect,resolve")
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:457)
at java.security.AccessController.checkPermission(AccessController.java:884)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051)
at java.net.Socket.connect(Socket.java:584)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:342)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:101)
有关如何解决此问题的任何想法?任何意见都非常感谢!
答案 0 :(得分:1)
我认为您的问题是您需要总共3个项目:
关键是客户端和服务器项目必须在项目内部具有接口(相同的接口)。
您的错误: java.lang.ClassNotFoundException:rmiserver.SomeInterface(没有安全管理器:禁用了RMI类加载器) 说它无法找到你的类:SomeInterface。 我不认为安全管理器是你真正的问题。
希望有所帮助。