运行 rmi 服务器,classnotfound

2022-09-01 12:21:05

嗨,我正在尝试运行一个将类绑定到命名服务器的java应用程序,但我不断得到一个ClassNotFoundException

首先,我启动注册表:

rmiregistry

然后从日食我尝试执行服务器,但得到这个错误

java.rmi.ServerException: RemoteException 发生在 server thread 中;嵌套的例外是:java.rmi.UnmarshalException: error unmarshalling arguments;嵌套的例外是: java.lang.ClassNotFoundException: progInternet2008.commons.NominabileFactory at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:396) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250) 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) atsun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535) at sun.rmi.transport.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:619) at java.lang.Thread.run(Thread.java:619) atsun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255) at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359) at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source) at progInternet2008.Pozzobon.tesi.Slave.main(Slave.java:54) Caused by: java.rmi.UnmarshalException: error unmarshalling arguments;嵌套的例外是: java.lang.ClassNotFoundException: progInternet2008.commons.NominabileFactory at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source) at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250) at sun.rmi.transport.Transport$1.run(Transport.java:159) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.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:619) Caused by: java.lang.ClassNotFoundException: progInternet2008.commons.NominabileFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) atjava.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:247) at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:711) at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:655) at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:592) at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:628) at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:294) at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:294) atsun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:238) at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1531) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1493) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) ...另外 12

我已经阅读了RMI Java教程,但仍然无法让它工作...

作为 VM 参数,我设置了以下内容:

-Djava.rmi.server.codebase=file:${workspace_loc}/progInternet2008

请帮帮我

(我使用的是 Java 6)


答案 1

从 /bin、/build 或 /build/classes 文件夹(以哪个文件夹是生成文件的根目录)运行该命令。rmiregisrty

我花了半天时间试图解决同样的事情。


答案 2

发生异常的原因是 rmiregistry 应用程序不知道从何处加载类。当您尝试绑定 RMI 注册表中的对象时,注册表将下载该对象的类定义。其他一些答案告诉您通过设置rmiregistry应用程序的类路径来解决此问题,以便它在启动时具有类定义并且不需要下载任何内容,但是Sun的Java RMI教程明确表示不要这样做。我怀疑这可能会导致注册表中的类版本与服务器上的类之间发生冲突。

处理此问题的正确方法是像您尝试的那样设置 java.rmi.server.codebase 属性。该属性要求目录路径以正斜杠结尾,如下所示:

-Djava.rmi.server.codebase=file:${workspace_loc}/progInternet2008/

如果 ${workspace_loc} 变量是相对路径,并且 rmiregistry 应用程序不是在同一目录中启动的,因此相对路径不正确,则也可能会遇到问题。如果使路径成为绝对路径,或者在相应的目录中启动 rmiregistry,则 ClassNotFoundException 应该会消失。有关更详细的信息,请参阅有关 java.rmi.server.codebase 属性的教程


推荐