簡體   English   中英

在運行可執行jar文件時找不到類錯誤(帶有Eclipse的導出RMI應用程序)

[英]Not found class error in running executable jar file (exported RMI application with eclipse)

我有一個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文件中找不到類文件?

添加

臨時解決方案如下:

java -Djava.rmi.server.codebase=file:/WHERE_THE_BIN_IS/bin/ -jar registry.jar 

我可以明確指向codebase目錄,但是jar文件中已經有相同的代碼。

當我執行rmiregister並設置代碼庫所在的CLASSPATH時,此問題已解決。

export CLASSPATH=SOMEWHERE_THE_LOCAL_BASE_IS_LOCATED
rmiregistry 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM