Hi I am trying to write a sample RMI application(using JDK 7). There are in all four classes that I have written:
RemoteDemo (RMI Interface class)
RemoteDemoImpl(RMI Implementation class, residing in the server)
RemoteDemoServer (RMI Server Application)
RemoteDemoClient (RMI Client application)
I have all the Java files under the following folder:
C:\1A<br/>
└───rmi<br/>
RemoteDemo.java
RemoteDemoClient.java
RemoteDemoImpl.java
RemoteDemoServer.java
The compiled code & the stub file code I have it placed in the folder having the structure as show below:
C:\1B
├───rmi
│ RemoteDemo.class
│ RemoteDemoImpl.class
│ RemoteDemoImpl_Stub.class
│ RemoteDemoServer.class
│
└───rmiClient
RemoteDemoClient.class
I have followed the following steps during the code compilation:
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
Now when I try to launch the server as show below:
C:\1A>java -cp %pathclass% rmi.RemoteDemoServer
I am getting the following error:
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)
The contents of the Java files are shown below:
a. Remote Interface
public interface RemoteDemo extends Remote {
public String doCommunicate(String args) throws RemoteException;
}
b. RemoteDemoImpl Class:
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/>
}
c. RemoteDemoServer Class:
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..........");
}
}