2016-10-23 23 views
0
CalculationServerRegistrationService server = new CalculationServerRegistrationService(); 
    ICalculationServerRegistrationService stub = (ICalculationServerRegistrationService) UnicastRemoteObject.exportObject(server, RMI_PORT); 
    // Bind the remote object's stub in the registry 
    Registry registry = LocateRegistry.getRegistry(); 
    registry.bind("ICalculationServerRegistrationService", stub); 
    new RMIServerTimeoutChecker().run(); 
} 

當我在同一臺機器上啓動rmiregistry的命令不帶參數,但裏面d:/ git的/ nnCloud/BE/nnCloudRESTService /目標/ classes文件夾,一切工作正常。但是,由於我需要兩個來自不同程序的服務器,因此我希望具有兩個代碼庫的單個rmiregistry,因此需要明確指定它,而不是在不同目錄中運行兩個「rmiregistry」命令。無法啓動RMI服務器時使用的代碼庫

我看到的唯一解決方案是運行

rmiregistry中-J-Djava.rmi.server.codebase =「文件:/ d:/ GIT中/ nnCloud/BE/nnCloudRESTService /目標/類文件中:/D:/ git/nnCloud/BE/nnCloudRESTService/target/classes「

這樣做後,我的應用程序崩潰在registry.bind。

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: com.mycompany.nncloudrestservice.serverservice.ICalculationServerRegistrationService 
+0

你有一個ClassNotFoundException後;最有可能的是,在你的一個設置中,**類路徑**不是它應該的。 – GhostCat

回答

0

代碼庫不會告訴當前JVM在哪裏找到類。 CLASSPATH就是這樣做的。代碼庫告訴下游JVM在哪裏找到類。

這裏正確的解決方案是運行每個JVM,該JVM使用適當的java.rmi.server.codebase參數導出和綁定遠程對象。不是註冊表。

+0

爲jvm設置-Djava.rmi.server.codebase也不起作用。 – 0x6B6F77616C74

+0

爲服務器JVM設置它?適用於我。 – EJP

0

有從運行rmiregistry的代碼後沒有問題,將LocateRegistry.createRegistry