Java 运行 rmi 服务器,classnotfound

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/464687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:57:52  来源:igfitidea点击:

running rmi server, classnotfound

javaeclipsermirmiregistry

提问by Maurizio Pozzobon

Hi I'm trying to run a java application that binds a class to the naming server, but i constantly get a ClassNotFoundException

嗨,我试图运行结合一个类来命名服务器的Java应用程序,但我不断地得到一个ClassNotFoundException

First I start the registry:

首先我启动注册表:

rmiregistry

注册

then from eclipse I try to execute the server but get this error

然后从 Eclipse 我尝试执行服务器但收到此错误

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 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) 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) 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: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; nested exception is: 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.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.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 sun.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 more

java.rmi.ServerException: 服务器线程发生远程异常;嵌套异常是: 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) at sun.rmi .transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535) 在 sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790) 在 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 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:359) at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source) at progInternet2008.Pozzobon.tesi.Slave.main(Slave.java:54) 由:java.rmi. UnmarshalException: 错误解组参数;嵌套异常是:java.lang.ClassNotFoundException: progInternet2008.commons.NominabileFactory at sun.rmi.registry.RegistryImpl_Skel。

I've read the RMI Java tutorial but still could not get it working...

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

As VM Arguments I've set this:

作为 VM 参数,我设置了这个:

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

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

please help me

请帮我

(I'm using Java 6)

(我使用的是 Java 6)

回答by falstro

I'm fairly certain that you'll have to start your RMI server using the same classpath as your application. I believe it takes the same parameters as java, i.e. -cp [your class path].

我相当确定您必须使用与应用程序相同的类路径来启动 RMI 服务器。我相信它采用与 java 相同的参数,即 -cp [your class path]

回答by Nathan Feger

Okay I just overcame this problem. Make sure when you run rmiregistrythat your CLASSPATHenvironment variable is set.

好的,我刚刚克服了这个问题。确保当你运行rmiregistry你的CLASSPATH环境变量设置。

For example, you might have a script:

例如,您可能有一个脚本:

set CLASSPATH=[path to jdbc driver].jar
rmiregistry.exe

This was all I needed to get my lost classpath working. I'm not sure how to send -cp commandlineto rmiregistry.exe. Its documentation is quite lacking.

这就是让我丢失的类路径工作所需的全部内容。我不确定如何发送-cp commandlinermiregistry.exe. 它的文档非常缺乏。

回答by A. Levy

The exception is occurring because the rmiregistry application doesn't know where to load classes from. When you attempt to bind an object in the RMI registry, the registry downloads the class definition for that object. Some of the other answers are telling you to get around this by setting the classpath for the rmiregistry app so that it has the class definitions when it is started and doesn't need to download anything, but Sun's Java RMI tutorial RMI)">explicitly says not to do this. I suspect this has the potential to cause conflicts between the version of the class in the registry and the class on the server.

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

The correct way to handle the problem is to set the java.rmi.server.codebase property as you were trying to do. The property requires that a directory path be terminated with a forward slash, like so:

处理该问题的正确方法是按照您尝试的方式设置 java.rmi.server.codebase 属性。该属性要求目录路径以正斜杠终止,如下所示:

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

You may also be having trouble if the ${workspace_loc} variable is a relative path and the rmiregistry application was not started in the same directory so the relative path is not correct for it. If you either make the path absolute, or start the rmiregistry in the appropriate directory, the ClassNotFoundException should go away. See the tutorial on the java.rmi.server.codebase propertyfor a little more detailed information.

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

回答by howl

try to add /bin at the end of your VM Arg:

尝试在 VM Arg 的末尾添加 /bin:

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

The file you will run are in this directory, so you need to include it in the path.

您将运行的文件在此目录中,因此您需要将其包含在路径中。

回答by Abraham

I spent a whole day uninstalling and reinstalling my JDK and changing the classpaths's and environment variables. But the culprit was that the command start rmigregistrydidnt' start rmiregistry in a proper way. So, thanks for the comments on this page the solution was to unsetthe CLASSPATH temporarily. And that is done through the command set CLASSPATH=

我花了一整天卸载并重新安装我的 JDK 并更改类路径和环境变量。但罪魁祸首是命令start rmigregistry没有以正确的方式启动 rmiregistry。因此,感谢您对此页面的评论,解决方案是暂时取消设置CLASSPATH。这是通过命令完成的set CLASSPATH=

回答by Munish Chandel

I upgraded from JDK1.6.0_33 to 1.7.0_45 and had the same problem. I found this document and resolved the problem by starting rmiregistry with:

我从 JDK1.6.0_33 升级到 1.7.0_45 并且遇到了同样的问题。我找到了这个文档并通过启动 rmiregistry 解决了这个问题:

rmiregistry -Djava.rmi.server.useCodebaseOnly=false

rmir​​egistry -Djava.rmi.server.useCodebaseOnly=false

Refer below http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/enhancements-7.html

请参阅以下 http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/enhancements-7.html

回答by Dylan R Coss

I had the same problem, to fix this ensure that your CLASSPATHis set to the path containing the server classes when running rmiregistry.

我遇到了同样的问题,要解决此问题,请确保在运行rmir​​egistry时将CLASSPATH设置为包含服务器类的路径。

On a linux machine run the following commands.

在 linux 机器上运行以下命令。

export CLASSPATH="<server_class_path>"

Ensure the CLASSPATHhas been set:

确保已设置CLASSPATH

echo $CLASSPATH

Once the class path has been set, run rmiregistry

设置类路径后,运行rmir​​egistry

rmiregistry &

回答by Marcelo Lazaroni

Run the rmiregisrtycommand from your /bin, /build, or /build/classes folder, whichever folder is the root of your built files.

rmiregisrty从 /bin、/build 或 /build/classes 文件夹运行命令,无论哪个文件夹是构建文件的根目录。

I spent half a day trying to solve that same thing.

我花了半天时间试图解决同样的问题。

回答by Atul Patel

Close the cmd window where the rmiregistry was initially started.In a fresh cmd go to the location where your project classfiles are located(uptill bin) and start the registry using the below command:

关闭最初启动 rmiregistry 的 cmd 窗口。在新的 cmd 中,转到项目类文件所在的位置(uptill bin)并使用以下命令启动注册表:

rmiregistry -J-Djava.rmi.server.useCodebaseOnly=false

rmir​​egistry -J-Djava.rmi.server.useCodebaseOnly=false

If you are using Eclipse ,Run the ServerSideProject and your ImplementationClass Instance gets bound to the URL specified.

如果您使用的是 Eclipse,请运行 ServerSideProject 并且您的 ImplementationClass 实例将绑定到指定的 URL。

Just print a line below the the binding method and see to it whether it is gets printed. If it gets printed successfully it means your server is working fine.

只需在绑定方法下方打印一行,看看它是否被打印出来。如果打印成功,则表示您的服务器工作正常。