RMI异常RemoteException嵌套异常

时间:2013-11-21 15:00:16

标签: java rmi netbeans-7

尝试运行RMI示例但遇到以下异常:

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;
}

1 个答案:

答案 0 :(得分:0)

我发现我必须在netbeans项目路径上:~/build/classes并在该路径上运行rmiregistry。

rmir​​egistry路径可以在 Tools-&gt;下找到。 netbeans中的Java平台。警告!按照以下示例更改为jre而不是jdk:
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/bin/rmiregistry