我有一个 RMI 应用程序的项目。 当我可以在 eclipse 下成功测试它们(使用 RMI Plugin )时,我尝试使用 eclipse 的导出功能将它们导出为 jar 文件。
问题是只有一个应用程序可以与导出的 jar 文件正常工作。
java -jar registry.jar
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: common.Registry <-- ???
错误消息显示未找到类。我解压jar文件发现jar文件中很好的导出了该类。
temp> unzip registry.jar
Archive: registry.jar
inflating: META-INF/MANIFEST.MF
creating: client/
inflating: client/ChatClientImpl.class
creating: common/
inflating: common/ChatRoomProvider.class
inflating: common/Entity.class
inflating: common/ChatRoomServer.class
inflating: common/ChatClient.class
inflating: common/Registry.class <<<---
这是从 rmiregistry 捕获的消息:
Exception dispatching call to [0:0:0, 0] in thread
"RMI TCP Connection(2)-146.6.53.181" at Sun Nov 03 20:33:25 CST 2013:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: common.Registry
这是发生错误的代码:
try {
// clients and providers can access with the name Registry
Naming.rebind("Registry", new RegistryImpl()); <--
} catch (Exception e) {
e.printStackTrace();
}
可能是什么问题?为什么jar文件在其jar文件中找不到class文件?
添加
临时解决办法如下:
java -Djava.rmi.server.codebase=file:/WHERE_THE_BIN_IS/bin/ -jar registry.jar
我可以明确指向代码库目录,但相同的代码已经在 jar 文件中。
最佳答案
当我执行 rmiregister 并设置代码库所在的 CLASSPATH 时,此问题得到解决。
export CLASSPATH=SOMEWHERE_THE_LOCAL_BASE_IS_LOCATED
rmiregistry
关于java - 运行可执行 jar 文件时未找到类错误(使用 eclipse 导出的 RMI 应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19760376/