RMI服务器调用抛出java.lang.ClassNotFoundException:compute.Compute

时间:2014-12-05 13:15:23

标签: java tomcat rmi

我正在尝试按照Oracle documentation for RMI

学习RMI

我已经为服务器端和客户端创建了类,类的详细信息如下:

compute.Compute -- Remote interface
compute.Task -- Normal interface
engine.ComputeEngine -- Class that implements remote interface

代码详细信息可以在以下链接的文档中看到:

http://docs.oracle.com/javase/tutorial/rmi/designing.html http://docs.oracle.com/javase/tutorial/rmi/implementing.html

我已按照下面链接中给出的步骤编译代码,我正在做的所有这些都在我的具有Ubuntu OS的机器上。

http://docs.oracle.com/javase/tutorial/rmi/compiling.html

现在根据以下链接,我已将客户端和服务器的策略文件放在路径:/home/user/public_html

http://docs.oracle.com/javase/tutorial/rmi/running.html

另外一个区别是我有tomcat服务器所以我把类文件放在Tomcat webapps和我的web应用程序下,所以我使用命令运行该类:

java -cp /home/user/src:. -Djava.rmi.server.codebase=http://myipaddress:8080/myapp/classes/compute.jar -Djava.rmi.server.hostname=myipaddress -Djava.security.policy=server.policy engine.ComputeEngine

现在,当我运行此应用程序时,我得到例外:

ComputeEngine exception:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: compute.Compute
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:419)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
    at sun.rmi.transport.Transport$1.run(Transport.java:177)
    at sun.rmi.transport.Transport$1.run(Transport.java:174)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:252)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:378)
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at engine.ComputeEngine.main(ComputeEngine.java:31)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: compute.Compute
    at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:409)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
    at sun.rmi.transport.Transport$1.run(Transport.java:177)
    at sun.rmi.transport.Transport$1.run(Transport.java:174)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: compute.Compute
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.rmi.server.LoaderHandler$Loader.loadClass(LoaderHandler.java:1206)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at sun.rmi.server.LoaderHandler.loadClassForName(LoaderHandler.java:1219)
    at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:729)
    at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:673)
    at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:610)
    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:1558)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1e exce514)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
    ... 13 more

例外java.lang.ClassNotFoundException: compute.Compute。但是我的compute.jar中的类文件位于我的/home/user/src路径中,我也可以使用http://myipaddress:8080/myapp/classes/compute.jar

的URL下载它

另外,仅供参考,我在机器上执行所有步骤,只需要没有任何单独的客户端和服务器机器。

有人可以帮助我如何解决这个问题?如果您需要任何进一步的细节,请告诉我,以便我们提供。

更新

我跟着@EJP在这篇文章中发出的asnwer - Is it necessary/important to set a classpath in the RMI registry?

然后我从我拥有rmiregistry的jar文件的目录启动Compute.class,然后运行以下命令:

java -cp /home/user/src:/home/user/public_html/classes/compute.jar -Djava.rmi.server.codebase=http://myipaddress:8080/myapp/classes/compute.jar -Djava.rmi.server.hostname=myipaddress -Djava.security.policy=server.policy engine.ComputeEngine

但我仍然得到同样的例外。

1 个答案:

答案 0 :(得分:0)

该类不在注册表的CLASSPATH上。