0
試圖運行RMI的例子,但面臨以下異常:RMI異常的RemoteException嵌套異常
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: hejsan.RemoteBuffer
我已經開始了rmiregristry,它似乎運行良好。但服務器沒有運行,只是建立並停止。 /Library/Java/JavaVirtualMachines/jdk1.7_45.jdk/Contents/Home/jre/bin/rmiregistry
項目名稱: HEJ
套餐名稱: hejsan
文件: MyBuffer.java和RemoteBuffer.java
MyBuffer.java:
package hejsan;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.LinkedList;
@SuppressWarnings("serial")
public class MyBuffer extends UnicastRemoteObject implements RemoteBuffer {
LinkedList<Integer> list = new LinkedList<Integer>();
public MyBuffer() throws RemoteException, MalformedURLException {
super();
Naming.rebind("rmi://localhost/buffer", this);
}
public synchronized void put(Integer i) throws RemoteException {
list.addLast(i);
notifyAll();
}
public synchronized Integer get() throws RemoteException {
while (list.size() == 0) {
try {
wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return (Integer) list.removeFirst();
}
public static void main(String[] args) {
try {
new MyBuffer();
} catch (RemoteException re) {
System.out.println(re);
System.exit(1);
} catch (MalformedURLException me) {
System.out.println(me);
System.exit(1);
}
}
}
RemoteBuffer .java:
package hejsan;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface RemoteBuffer extends Remote {
void put(Integer i) throws RemoteException;
Integer get() throws RemoteException;
}