JDK7u21的发行说明指定了与RMI相关的更改:
From this release, the RMI property java.rmi.server.useCodebaseOnly is set to true by default. In previous releases the default value was false.
This change of default value may cause RMI-based applications to break unexpectedly. The typical symptom is a stack trace that contains a java.rmi.UnmarshalException containing a nested java.lang.ClassNotFoundException.
If these exceptions occur, the preferred way to solve the problem is to configure all RMI clients and servers to use the same codebase, by specifying proper values in the java.rmi.server.codebase system property. This is typically done by adding the -D option to the command that starts up the application: java -Djava.rmi.server.codebase=file:////(path-to-remote-classes)/
文档中也指定了here该解决方法是将 java.rmi.server.useCodebaseOnly 属性设置回 false。
但是,即使我明确将此属性设置为 false,我也会收到上面提到的异常。请问这里有什么线索吗?
如果我必须通过上述首选方式解决它(通过设置 -Djava.rmi.server.codebase=file:////(path-to-remote-classes)/,那么哪个路径应该我设置在这里?我的工作区/垃圾箱?
最佳答案
您必须确保在使用远程类的所有 JVM 上设置属性。这包括您的 RMI 服务器、RMI 客户端、和 RMI 注册表。如果它们都在同一台机器上,那么您可以将它们全部设置为指向类位置的 file:
URL 。如果它们不在同一台计算机上,那么您可以使用 HTTP 服务器使这些类可用,然后将远程 JVM(可能是客户端)的 codebase 属性设置为使用 http:
URL这指出了可以类的地方。或者,您可以通过其他方式使这些类可供远程 JVM 使用,例如复制它们或使用共享文件系统,然后将代码库属性设置为 file:
URL。
您尝试将 java.rmi.server.useCodebaseOnly
设置为 false
的解决方法可能不起作用,原因如下:您可能没有将其设置为所有交互的 JVM,或者您可能没有将 codebase 属性设置为正确的值。
由于您必须费尽心思配置注册表和所有客户端,因此您不妨将其 codebase
属性设置为正确的 URL,而不是采用设置的解决方法useCodebaseOnly
更改为 false
。
关于java - JDK7u21 RMI 更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18358498/