title: Getting ClassNotFoundException when trying to run simple java rmi
body: <p>I am new to java RMI and was trying to run sample java rmi program. But I am getting java.rmi.notboundexception . Below is my code. </p>
  
  <p>server code </p>
  
  <pre><code>server.java 
  
  import java.rmi.registry.Registry;
  import java.rmi.registry.LocateRegistry;
  import java.rmi.RemoteException;
  import java.rmi.server.UnicastRemoteObject;
  
  public class Server implements Hello {
  
  public Server() {}
  
  public String sayHello() {
  return "Hello, world!";
  }
  
  public static void main(String args[]) {
  Hello stub = null;
  Registry registry = null;
  
  try {
      Server obj = new Server();
      stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
      registry = LocateRegistry.getRegistry();
      registry.bind("Hello", stub);
  
      System.err.println("Server ready");
  } catch (Exception e) {
      System.err.println("Server exception: " + e.toString());
      e.printStackTrace();
  
  /*  Rewritten as per EJP's remarks 
      try{
  // Line 66 , where the error is pointing 
      registry.unbind("Hello");
      registry.bind("Hello",stub);
          System.err.println("Server ready");
      }catch(Exception ee){
      System.err.println("Server exception: " + ee.toString());
          ee.printStackTrace();
      }
  }
  */ 
  
  
  }
  } 
  </code></pre>
  
  <p>client code 
      client.java </p>
  
  <pre><code>import java.rmi.registry.LocateRegistry;
  import java.rmi.registry.Registry;
  
  public class Client {
  
  private Client() {}
  
  public static void main(String[] args) {
  
  String host = (args.length &lt; 1) ? null : args[0];
  try {
      Registry registry = LocateRegistry.getRegistry(host);
      Hello stub = (Hello) registry.lookup("Hello");
      String response = stub.sayHello();
      System.out.println("response: " + response);
  } catch (Exception e) {
      System.err.println("Client exception: " + e.toString());
      e.printStackTrace();
  }
  }
  }
  </code></pre>
  
  <p>Interface code </p>
  
  <p>Hello.java </p>
  
  <pre><code>import java.rmi.Remote;
  import java.rmi.RemoteException;
  
  public interface Hello extends Remote {
      String sayHello() throws RemoteException;
  }
  </code></pre>
  
  <p>Steps followed </p>
  
  <ol>
  <li><p>javac Server.java</p></li>
  <li><p>javac Client.java</p></li>
  <li><p>Start the Java RMI registry with below command</p></li>
  </ol>
  
  <p>start rmiregistry</p>
  
  <p>After these, when i run the server with java server command , I am getting below exception. Exception changed from the original post after implementing the changes mentioned by EJP.</p>
  
  <pre><code>C:\Users\hp\Desktop\NUS Modules\Distributed systems\Assignment1\HelloWorld\Hello
  World\Server&gt;java Server
  Server exception: java.rmi.ServerException: RemoteException occurred in server t
  hread; nested exception is:
      java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
  tion is:
      java.lang.ClassNotFoundException: Hello
  java.rmi.ServerException: RemoteException occurred in server thread; nested exce
  ption is:
      java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
  tion is:
      java.lang.ClassNotFoundException: Hello
      at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:420
  )
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:268)
      at sun.rmi.transport.Transport$1.run(Transport.java:178)
      at sun.rmi.transport.Transport$1.run(Transport.java:175)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:174)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:5
  57)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTranspor
  t.java:812)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
  .java:671)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
  java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
  .java:617)
      at java.lang.Thread.run(Thread.java:745)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
  RemoteCall.java:276)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
  253)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:379)
      at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
      at Server.main(Server.java:61)
  Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested ex
  ception is:
      java.lang.ClassNotFoundException: Hello
      at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
      at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:410
  )
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:268)
      at sun.rmi.transport.Transport$1.run(Transport.java:178)
      at sun.rmi.transport.Transport$1.run(Transport.java:175)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:174)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:5
  57)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTranspor
  t.java:812)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
  .java:671)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
  java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
  .java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.ClassNotFoundException: Hello
      at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.rmi.server.LoaderHandler$Loader.loadClass(LoaderHandler.java:1207
  )
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:340)
      at sun.rmi.server.LoaderHandler.loadClassForName(LoaderHandler.java:1221 
  )
      at sun.rmi.server.LoaderHandler.loadProxyInterfaces(LoaderHandler.java:7
  31)
      at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:674)
      at sun.rmi.server.LoaderHandler.loadProxyClass(LoaderHandler.java:611)
      at java.rmi.server.RMIClassLoader$2.loadProxyClass(RMIClassLoader.java:6
  46)
      at java.rmi.server.RMIClassLoader.loadProxyClass(RMIClassLoader.java:311
  )
      at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStrea
  m.java:255)
      at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1559)
      at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1515)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
  774)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)
      ... 13 more
  </code></pre>
  
  <p>Please help to solve this error . Anything wrong in the code or any firewall settings need to be done. </p>
  
  <p>java version - 1.8 
  operating system - Windows 7</p>