【问题标题】:Not found class error in running executable jar file (exported RMI application with eclipse)Not found class error in running executable jar file (exported RMI application with eclipse)
【发布时间】:2013-11-14 15:18:45
【问题描述】:

我有一个 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 文件中。

【问题讨论】:

    标签: java jar rmi


    【解决方案1】:

    当我执行 rmiregister 并设置代码库所在的 CLASSPATH 时,此问题已解决。

    export CLASSPATH=SOMEWHERE_THE_LOCAL_BASE_IS_LOCATED
    rmiregistry 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-31
      • 1970-01-01
      • 1970-01-01
      • 2014-03-22
      • 2021-11-03
      • 1970-01-01
      • 1970-01-01
      • 2020-11-28
      相关资源
      最近更新 更多