2013-10-23 78 views
0

所以我剛剛開始使用RMI和 我建立這個類服務器端:如何在java中設置RMI?

public interface ServiceServer extends Remote 
public class ServiceServerImpl extends UnicastRemoteObject implements ServiceServer 
public interface Service extends Serializable 

而這個類客戶端:

public class ServiceBrowser 

當我嘗試運行我的程序我得到這個例外:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
java.lang.ClassNotFoundException: FirstTryRMI.ServiceServer 

據我所知,問題是與RMI沒有找到類(?)。 我已經看遍了,我似乎無法理解,我如何將我的課堂文件添加到正確的位置?

回答

0

請確保您的客戶端也包含jar文件,它必須具有ServiceServer類。

+0

這是他將得到的下一個問題,但目前的問題是註冊表無法看到該類。 – EJP

+0

我幾年沒有完成RMI,但我從來沒有記得必須將客戶端jar放在rmiregistry classpath中。 –

+0

那麼註冊表究竟是從哪裏獲取遠程接口和存根類呢?看看堆棧跟蹤。他有一個包含UnmarshalException的ServerException。所以他所調用的任何服務器都沒有CLASSPATH中的類。這隻能是註冊表。也許在你的情況下,你使用LocateRegistry而不是rmiregistry命令。 – EJP

0

您需要確保註冊表的遠程接口,存根等位於其CLASSPATH上。