正在运行 rmi 服务器,未找到类
您好,我正在尝试运行一个将类绑定到命名服务器的 java 应用程序,但我不断收到 ClassNotFoundException
首先,我启动注册表:
rmi注册表
然后从 eclipse 我尝试执行服务器但收到此错误
java.rmi.ServerException:服务器线程中发生RemoteException; 嵌套异常是: java.rmi.UnmarshalException:解组参数时出错; 嵌套异常是: java.lang.ClassNotFoundException: progInternet2008.commons.NominabileFactory 在 sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:396) 在 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250) 在 sun.rmi.transport.Transport$1.run(Transport.java:159) 在 java.security.AccessController.doPrivileged(本机方法) 在 sun.rmi.transport.Transport.serviceCall(Transport.java:155) 在 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) 在 java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 在 java.lang.Thread.run(Thread.java:619) 在 sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255) 在 sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233) 在 sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359) 在 sun.rmi.registry.RegistryImpl_Stub.rebind(来源未知) 在 progInternet2008.Pozzobon.tesi.Slave.main(Slave.java:54) 引起原因:java.rmi.UnmarshalException:解组参数时出错; 嵌套异常是: java.lang.ClassNotFoundException: progInternet2008.commons.NominabileFactory 在 sun.rmi.registry.RegistryImpl_Skel.dispatch(来源未知) 在 sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386) 在 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250) 在 sun.rmi.transport.Transport$1.run(Transport.java:159) 在 java.security.AccessController.doPrivileged(本机方法) 在 sun.rmi.transport.Transport.serviceCall(Transport.java:155) 在 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) 在 java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 在 java.lang.Thread.run(Thread.java:619) 引起原因:java.lang.ClassNotFoundException:progInternet2008.commons.NominabileFactory 在 java.net.URLClassLoader$1.run(URLClassLoader.java:200) 在 java.security.AccessController.doPrivileged(本机方法) 在 java.net.URLClassLoader.findClass(URLClassLoader.java:188) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:307) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:252) 在 java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) 在 java.lang.Class.forName0(本机方法) 在 java.lang.Class.forName(Class.java:247) 在 sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:711) 在 sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:655) 在 sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:592) 在 java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:628) 在 java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:294) 在 sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:238) 在 java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1531) 在 java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1493) 在 java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732) 在 java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) 在 java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) ... 12 更多
我已经阅读了 RMI Java 教程,但仍然无法让它工作...
作为 VM 参数,我设置了这个:
-Djava.rmi.server.codebase=文件:${workspace_loc}/progInternet2008
请帮助我
(我正在使用 Java 6)
Hi I'm trying to run a java application that binds a class to the naming server, but i constantly get a ClassNotFoundException
First I start the registry:
rmiregistry
then from eclipse I try to execute the server but get this error
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
I've read the RMI Java tutorial but still could not get it working...
As VM Arguments I've set this:
-Djava.rmi.server.codebase=file:${workspace_loc}/progInternet2008
please help me
(I'm using Java 6)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
从 /bin、/build 或 /build/classes 文件夹(无论哪个文件夹是构建文件的根目录)运行
rmiregisrty
命令。我花了半天时间试图解决同样的问题。
Run the
rmiregisrty
command from your /bin, /build, or /build/classes folder, whichever folder is the root of your built files.I spent half a day trying to solve that same thing.
发生异常是因为 rmiregistry 应用程序不知道从哪里加载类。 当您尝试绑定 RMI 注册表中的对象时,注册表会下载该对象的类定义。 其他一些答案告诉您通过设置 rmiregistry 应用程序的类路径来解决这个问题,以便它在启动时具有类定义并且不需要下载任何内容,但是 Sun 的 Java RMI 教程 明确表示不要执行此操作。 我怀疑这有可能导致注册表中的类版本与服务器上的类版本之间发生冲突。
处理问题的正确方法是按照您的尝试设置 java.rmi.server.codebase 属性。 该属性要求目录路径以正斜杠终止,如下所示:
如果 ${workspace_loc} 变量是相对路径并且 rmiregistry 应用程序未在同一目录中启动,因此相对路径为不正确。 如果您将路径设置为绝对路径,或者在适当的目录中启动 rmiregistry,则 ClassNotFoundException 应该消失。 请参阅教程有关 java.rmi.server.codebase 属性 的更多详细信息。
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 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.
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:
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 property for a little more detailed information.
好吧,我刚刚克服了这个问题。 确保运行
rmiregistry
时设置了CLASSPATH
环境变量。例如,您可能有一个脚本:
这就是我让丢失的类路径正常工作所需的全部内容。 我不确定如何将
-cp 命令行
发送到rmiregistry.exe
。 它的文档非常缺乏。Okay I just overcame this problem. Make sure when you run
rmiregistry
that yourCLASSPATH
environment variable is set.For example, you might have a script:
This was all I needed to get my lost classpath working. I'm not sure how to send
-cp commandline
tormiregistry.exe
. Its documentation is quite lacking.我相当确定您必须使用与应用程序相同的类路径来启动 RMI 服务器。 我相信它采用与java相同的参数,即-cp
[your class path]
。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]
.我从JDK1.6.0_33升级到1.7.0_45,也遇到了同样的问题。 我找到了此文档并通过启动 rmiregistry 解决了问题:
rmiregistry -Djava.rmi.server.useCodebaseOnly=false
请参阅下文
http://docs.oracle.com/javase /7/docs/technotes/guides/rmi/enhancements-7.html
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:
rmiregistry -Djava.rmi.server.useCodebaseOnly=false
Refer below
http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/enhancements-7.html
关闭最初启动 rmiregistry 的 cmd 窗口。在新的 cmd 中,转到项目类文件所在的位置(uptill bin)并使用以下命令启动注册表:
如果您使用 Eclipse,请运行 ServerSideProject 并且您的 ImplementClass 实例将绑定到指定的 URL。
只需在绑定方法下方打印一行,然后查看它是否被打印。 如果成功打印,则意味着您的服务器工作正常。
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:
If you are using Eclipse ,Run the ServerSideProject and your ImplementationClass Instance gets bound to the URL specified.
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.
尝试在 VM 末尾添加 /bin Arg:
您将运行的文件位于此目录中,因此您需要将其包含在路径中。
try to add /bin at the end of your VM Arg:
The file you will run are in this directory, so you need to include it in the path.
我遇到了同样的问题,要解决此问题,请确保在运行 rmiregistry 时将您的 CLASSPATH 设置为包含服务器类的路径。
在 Linux 机器上运行以下命令。
确保已设置CLASSPATH:
设置类路径后,运行rmiregistry
I had the same problem, to fix this ensure that your CLASSPATH is set to the path containing the server classes when running rmiregistry.
On a linux machine run the following commands.
Ensure the CLASSPATH has been set:
Once the class path has been set, run rmiregistry
我花了一整天的时间卸载并重新安装 JDK 并更改类路径和环境变量。 但罪魁祸首是命令 start rmigregistry 没有以正确的方式启动 rmiregistry。 因此,感谢本页的评论,解决方案是暂时取消设置 CLASSPATH。 这是通过命令
set CLASSPATH=
完成的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 rmigregistry didnt' start rmiregistry in a proper way. So, thanks for the comments on this page the solution was to unset the CLASSPATH temporarily. And that is done through the command
set CLASSPATH=