无法弄清楚为什么在编写示例RMI应用程序时抛出由于ClassNotFoundException引起的UnMarshalException

时间:2015-08-04 08:18:17

标签: java rmi

您好我正在尝试编写示例RMI应用程序(使用JDK 7)。我写的所有四个班都有:

RemoteDemo (RMI Interface class)
RemoteDemoImpl(RMI Implementation class, residing in the server)
RemoteDemoServer (RMI Server Application)
RemoteDemoClient (RMI Client application)

我拥有以下文件夹下的所有Java文件:

C:\1A<br/>
└───rmi<br/>
    RemoteDemo.java
    RemoteDemoClient.java
    RemoteDemoImpl.java
    RemoteDemoServer.java

已编译的代码&amp;存根文件代码我将它放在具有如下所示结构的文件夹中:

C:\1B
├───rmi
│   RemoteDemo.class
│   RemoteDemoImpl.class
│   RemoteDemoImpl_Stub.class
│   RemoteDemoServer.class
│
└───rmiClient
    RemoteDemoClient.class

我在代码编译期间遵循了以下步骤:

set path="C:\Program Files (x86)\Java\jdk1.7.0_75\bin"
set pathclass1="C:\1A"
set pathclass2="C:\1B"
set pathclass=%pathclass1%;%pathclass2%;. 
<b>C:\1A>javac -d %pathclass2% -cp %pathclass% rmi\RemoteDemo.java
C:\1A>javac -d %pathclass2% -cp %pathclass% rmi\RemoteDemoImpl.java
C:\1A>javac -d %pathclass2% -cp %pathclass% rmi\RemoteDemoServer.java
C:\1A>javac -d %pathclass2% -cp %pathclass% rmi\RemoteDemoClient.java
C:\1A>rmic  -d %pathclass2% -classpath %pathclass% rmi.RemoteDemoImpl

现在,当我尝试按下图所示启动服务器时:

C:\1A>java -cp %pathclass% rmi.RemoteDemoServer

我收到以下错误:

Exception in thread "main" java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
        java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
        java.lang.ClassNotFoundException: rmi.RemoteDemoImpl_Stub
        at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:419)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:267)
        at sun.rmi.transport.Transport$2.run(Transport.java:202)
        at sun.rmi.transport.Transport$2.run(Transport.java:199)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:198)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:567)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.access$400(TCPTransport.java:619)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$1.run(TCPTransport.java:684)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$1.run(TCPTransport.java:681)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:681)
        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:745)
        at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275)
        at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:252)
        at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:378)
        at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
        at java.rmi.Naming.bind(Naming.java:128)
        at rmi.RemoteDemoServer.main(RemoteDemoServer.java:10)

Java文件的内容如下所示:
一个。远程接口

public interface RemoteDemo extends Remote {    
    public String doCommunicate(String args) throws RemoteException;
}

湾RemoteDemoImpl类:

    public class RemoteDemoImpl extends UnicastRemoteObject implements RemoteDemo {<br/>
      private static final long serialVersionUID=1L;<br/>   
      public RemoteDemoImpl() throws RemoteException{<br/>
      super();<br/>
      }<br/>
      public String doCommunicate(String args) throws RemoteException {<br/>
      return "Server says:Hi " + args + "\n";<br/>
      }<br/>
      }

℃。 RemoteDemoServer类:

public class RemoteDemoServer {

 public static void main(String[] args) throws Exception {

    RemoteDemoImpl rmiDemoImpl = new RemoteDemoImpl();
    Naming.bind("RMIDemo", rmiDemoImpl);
    System.out.println("RMI Demo object bound to the name 'RMIDemo' and is ready for use..........");
}

}

1 个答案:

答案 0 :(得分:0)

查看堆栈跟踪。它发生在bind(),上,而且是ServerException。因此,注册表在其类路径中没有该类。