RMI - Unmarshalled Exception

时间:2014-03-25 11:49:52

标签: java rmi unmarshalling

我似乎无法让这个工作。我只是看它为实验室的基本指导,但我根本没有RMI的经验。我似乎无法理解为什么我会收到错误。

服务器

    public static void runServer() {
        // Install security manager, if none is present
        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new SecurityManager());
        }
        try {
            Registry registry = LocateRegistry.getRegistry();
            System.out.println("Reg: " + registry.toString());
            String name = "Server";
            Server server = new Server();
            I_Server stub = (I_Server) UnicastRemoteObject.exportObject(server, 0);

            registry.rebind(name, stub);
            System.out.println("All is well :-)\n");
        } catch (RemoteException re) {
            System.err.println("Remote Exception in DisplayGetEngine.main()\n");
            re.printStackTrace();
        }
    }

}

我在NetBeans中有以下运行命令和参数

参数:-cp C:\ rmi \ Server \ src; C:\ rmi \ Server \ dist \ Server.jar -Djava.rmi.server.codebase = file:/ C:/ rmi / Server / dist / Server的.jar

工作目录:C:\ rmi \ Server

我的stacktrace是重新绑定方法。

Reg: RegistryImpl_Stub[UnicastRef [liveRef: [endpoint:[10.50.18.205:1099](remote),objID:[0:0:0, 0]]]]
Remote Exception in DisplayGetEngine.main()

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: server.I_Server
    at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:419)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
    at sun.rmi.transport.Transport$1.run(Transport.java:177)
    at sun.rmi.transport.Transport$1.run(Transport.java:174)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:377)
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at server.Server.runServer(Server.java:50)
    at server.Server.main(Server.java:31)

如果我不运行rmiregistry,这是我的stacktrace

DisplayGetEngine.main()

中的远程异常
java.rmi.ConnectException: Connection refused to host: 10.50.18.205; nested exception is: 
    java.net.ConnectException: Connection refused: connect
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
    at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:340)
    at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
    at server.Server.runServer(Server.java:50)
    at server.Server.main(Server.java:31)

3 个答案:

答案 0 :(得分:0)

首先尝试调用createRegistry()以确保您有正在运行的注册表。此外,端口0应该是保留端口,因此您无法使服务器侦听该特定端口。尝试默认的1099。

答案 1 :(得分:0)

运行rmiregistry没有问题。如果仔细研究堆栈跟踪,问题似乎是ClassNotFoundException,而参数在rmi注册表中被解组。在类路径中运行它时,您必须检查RMI服务器的代码库是否在Server.jar中存在server.I_Server类。

来自RMI常见问题解答

  

A.4为什么我会收到ClassNotFoundException?   很可能java.rmi.server.codebase属性尚未在导出远程对象的VM上设置(或未正确设置)。请使用Java RMI(使用java.rmi.server.codebase属性)查看我们的教程Dynamic code downloading

答案 2 :(得分:0)

问题出在构建文件中。我需要插入此声明。

<target name="startRMI" depends="init">
<exec executable="C:\Program\Files\Java\jdk1.7.0_51\jre\bin\rmiregistry"
dir="${build.classes.dir}"></exec>
</target>