2013-10-23 26 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上。