我正在运行RMI应用程序而没有安全管理器:RMI类加载器禁用异常

时间:2013-06-27 19:10:11

标签: java eclipse-plugin classpath rmi rmiregistry

这是完整的例外:

Computeappengine exceptionRemoteException occurred in server thread; nested exception is: 
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: Client.prog (no security manager: RMI class loader disabled)
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: Client.prog (no security manager: RMI class loader disabled)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:334)
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:662)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
at Engine.ComputeappEngine_Stub.executeTask(Unknown Source)
at Client.computeappprog.main(computeappprog.java:23)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: Client.prog (no security manager: RMI class loader disabled)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
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:662)
Caused by: java.lang.ClassNotFoundException: Client.prog (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:373)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:163)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1574)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:306)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:288)
... 9 more

我的客户端软件包包含两个类Computeappproj,其中包含mainprog

我已经搜索了1000个论坛。什么都没有帮助。

希望有一些积极的东西

和好

可能是......

2 个答案:

答案 0 :(得分:5)

问题实际上在于类加载。当您通过RMI传输一些非jdk对象(即您自己类的对象)时,您需要确保JVM,客户端和服务器都在类路径中具有您的自定义类。在您的情况下,服务器缺少Client.prog类,因此无法从二进制表示重构对象 - Client.prog类字节码是必需的。 通常有两种方法可以解决此问题:

  1. 简单一:将所有数据传输对象类复制到客户端和服务器的类路径中。所以他们都不会与未知的课程混淆。对于某种程度上的严重,您甚至可能希望使用DTO类创建单独的JAR以便于维护。

  2. 挑战一:启用远程类加载。简而言之,如果需要,此技术使您的服务器可以从客户端下载类字节码,反之亦然。此选项有明显的安全问题(下载潜在的不安全代码),因此默认情况下禁用它。要启用它,您应该使用-Djava.rmi.server.codebase属性并定义URL,并设置适当的类加载器(RMIClassloader或它的后代)以使Java安全系统满意。以下是一些背景理论和故障排除指南的有用链接:link

答案 1 :(得分:1)

  

我正在运行RMI应用程序而没有安全管理器:RMI类加载器禁用异常

没有。再次读取堆栈跟踪。这里的例外java.lang.ClassNotFoundException: Client.prog。括号中的东西只是一个(字面上是括号的)注释,其中一个可能的原因之一。

问题Client.prog不在服务器的CLASSPATH上。你可以从这一行告诉我们:

java.rmi.ServerException: RemoteException occurred in server thread

解决方案是将类部署到服务器或使用代码库功能。