2013-11-21 116 views
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; 
} 

回答

0

我發現我必須在NetBeans項目路徑:~/build/classes並在該路徑上運行rmiregistry。

rmiregistry路徑可以在工具 - > Java平臺在netbeans中找到。警告!更改爲jre而不是jdk,請遵循以下示例:
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/bin/rmiregistry

相關問題