我使用 RMI 编写了一个简单的程序。当我想将服务绑定(bind)到注册表时,它会抛出以下异常:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: hw2.RMI.Server.RMIServer_Stub
此外,在 RMI VM 属性中,java.rmi.server.codebase
的值,我使用从类路径计算按钮来生成这 2 个 URL:
file:${workspace_loc:/rmiServer/bin} ( server)
file:${workspace_loc:/rmiInterface/bin} ( interface)
我使用 java-open jdk64 && JRE 系统库 [JavaSE-1.6] && 从 this site 安装 eclipse 插件
我找不到任何好的解决方案来解决我的问题,有人可以帮助我吗?
最佳答案
我记得我在某处读过(如下所示: http://docs.oracle.com/javase/6/docs/technotes/guides/rmi/codebase.html ,第 6.0 节),如果您在 java.rmi.server.codebase 中使用目录,则需要以尾部斜杠结尾。
另一方面,使用类路径运行独立的 RMI 注册表很简单:您需要设置 CLASSPATH 环境变量,然后在 shell 中运行 rmiregistry。即使在启动服务器时没有指定 java.rmi.server.codebase 也为我工作。
顺便说一句。如果您需要 java.rmi.server.codebase 接受的 file: URL 格式的一些示例,您可以在这里找到一些: http://docs.oracle.com/javase/tutorial/rmi/running.html关于java - 使用 RMI 时注册表绑定(bind)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21170338/