我是RMI的新手,并且正在 here 上关注Oracle的RMI教程代码,并写了类似的内容。
我的代码工作正常,一切正常。但是我没有接触到代码,今天在我刚刚来到并试图再次运行它的3周之后,令人惊讶地它不再运行,并抛出以下异常:(当然我做了start rmiregistry
)。
如何解决问题?我正在运行Java 1.8.0.60并使用eclipse。
解决方案:我应该在rmiregistry
文件夹中运行bin
(或者可能用其他方式设置类路径)。
Server exception: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: test.Hello
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: test.Hello
... continued ...
以下是HelloServer
的代码:
package test;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class HelloServer implements Hello {
public HelloServer() {}
public String pollServer() {
String data= EchoServerRMI.queuePoll();
System.out.println("polling test"+data);
return data;
// return "1";
}
public static void main(String args[]) {
try {
HelloServer obj = new HelloServer();
Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry();
registry.bind("Hello", stub);
System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}
以下是Hello
类的代码:
package test;
import java.rmi.*;
public interface Hello extends Remote {
String pollServer() throws RemoteException;
}