java服务器在命名时中断。重新绑定
我正在服务器上做一个议程,一切都很顺利,我启动了RMI注册表,服务器工作正常,我测试了代码,我可以登录了。
现在,我想开始将代码放在方法中,并从服务器在客户机中调用它们,当我将Naming.rebind("server", i);
放在服务器中调用方法时,代码中断
我的项目包含三个类:服务器类、客户端类和从服务器向客户端调用方法的接口类。这是服务器的代码:
public class ServerAgendas extends UnicastRemoteObject
implements InterfaceServer {
private static final long serialVersionUID = 1L;
protected ServerAgendas() throws RemoteException {
super();
// TODO Auto-generated constructor stub
}
static String Clientusername;
static String Clientpassword;
public static void main (String args[]) throws NotBoundException,
IOException {
System.out.println("1");
try{
InterfaceServer i = new ServerAgendas();
System.out.println("2");
Naming.rebind("server",i);
System.out.println("Serveur agendas pret");
}
catch (Exception e){
System.err.println("Error "+e.getMessage());
}
ServerSocket ASocket = new ServerSocket(portNumber);
Socket connectionSocket = ASocket.accept();
}
public boolean login(String ClientUsername, String ClientPassword)
throws IOException, SQLException {
}
在客户端,我使用它调用以下方法:
InterfaceServer i = (InterfaceServer)Naming.lookup("server");
System.out.println(i.login(username, password));
界面包括:
public interface InterfaceServer extends Remote{
public boolean login(String Clientusername, String Clientpassword)
throws RemoteException, IOException, SQLException;
首先运行注册表,然后运行服务器,控制台显示:
1
2
Error RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: InterfaceServer
我使用1和2来查看它在哪里断开,它正在断开:
Naming.rebind("server",i);
我需要做什么来避免发生此异常
# 1 楼答案
消息中提到的类在其类路径上对注册表不可用
解决这个问题和其他几个问题的最简单方法是在服务器JVM中使用LocaterRegistry运行注册表。createRegistry()
否则,您必须弄清楚如何使用CLASSPATH参数启动rmiregistry命令,或者使用codebase特性,这完全是另一回事