title: Java RMI Eclipse ClassNotFound and .lookup(Unknown Source) in client/server/both
body: <p>the problem seems to be quite popular -> ClassNotFoundException when running RMI server using Eclipse IDE... Sure, I digged deep in every possible way of setting the codebase parameter in RMI Eclipse Plugin from <a href="http://www.genady.net" rel="nofollow">http://www.genady.net</a> nothing worked with that code in SERVER's main:</p>
  
  <pre><code>try{
      Registry r = LocateRegistry.getRegistry(1099);
      r.rebind("SERVER", new RemotePrinterImpl());
      System.out.println("SERVER STARTED!");
  }catch(Exception e){
      e.printStackTrace();
  }
  </code></pre>
  
  <p>or with pre-started RMIRegistry on 1099:</p>
  
  <pre><code>try{
      Naming.rebind("SERVER", new RemotePrinterImpl());
      System.out.println("SERVER STARTED!");
  }catch(Exception e){
      e.printStackTrace();
  }
  </code></pre>
  
  <p>ClassNotFound when it came to Server Impl Stub... 
  after hours of pulling my hair off, I decided to create registry in try block and than use it to register my server:</p>
  
  <pre><code>try{
          Registry r = LocateRegistry.createRegistry(1099);
      Naming.rebind("SERVER", new RemotePrinterImpl());
      System.out.println("SERVER STARTED!");
  }catch(Exception e){
      e.printStackTrace();
  }
  </code></pre>
  
  <p>IT WORKED!!! Superb, but than Client execution produced this:</p>
  
  <pre><code>java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
       java.lang.ClassNotFoundException: demo.rmi.print.server.RemotePrinterImpl_Stub
       at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
       at java.rmi.Naming.lookup(Naming.java:101)
       at demo.rmi.print.client.PrintClient.main(PrintClient.java:15)
  Caused by: java.lang.ClassNotFoundException: demo.rmi.print.server.RemotePrinterImpl_Stub
       at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
       at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
       at sun.rmi.server.LoaderHandler$Loader.loadClass(LoaderHandler.java:1208)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
       at java.lang.Class.forName0(Native Method)
       at java.lang.Class.forName(Class.java:270)
       at sun.rmi.server.LoaderHandler.loadClassForName(LoaderHandler.java:1221)
       at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:454)
       at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:185)
       at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:637)
       at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:264)
       at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:222)
       at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1610)
       at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1515)
       at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)
       at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)
       at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
       ... 3 more
  </code></pre>
  
  <p>and I do not have slightest idea what I should do... Is the RMIRegistry somehow messed up? Is it the code's fault?</p>
  
  <p>Please help me if you can.</p>
  
  <p>Here are the codes, print-server, print-client, print-common ( with shared Interface ):</p>
  
  <pre><code>package demo.rmi.print.common;
  
  import java.rmi.Remote;
  import java.rmi.RemoteException;
  
  public interface RemotePrinter extends Remote {
  
      public String getPrinterStatus() throws RemoteException;
  
  }
  </code></pre>
  
  <p>//////////////////////////////////////////////////////</p>
  
  <pre><code>package demo.rmi.print.server;
  
  import java.rmi.Naming;
  import java.rmi.RemoteException;
  import java.rmi.registry.LocateRegistry;
  import java.rmi.registry.Registry;
  import java.rmi.server.UnicastRemoteObject;
  
  import demo.rmi.print.common.RemotePrinter;
  
  public class RemotePrinterImpl extends UnicastRemoteObject implements
          RemotePrinter {
  
      public RemotePrinterImpl() throws RemoteException{
          super();
      }
  
      @Override
      public String getPrinterStatus() throws RemoteException {
          System.out.println("Requested STATUS?");
          return "OK";
      }
  
      public static void main(String[] args) {
  
          try{
              Registry r = LocateRegistry.createRegistry(1099);
              r.rebind("SERVER", new RemotePrinterImpl());
              System.out.println("SERVER STARTED!");
          }catch(Exception e){
              e.printStackTrace();
          }
  
      }
  
  }
  </code></pre>
  
  <p>//////////////////////////////////////////////////////</p>
  
  <pre><code>package demo.rmi.print.client;
  
  import java.rmi.Naming;
  import java.rmi.RMISecurityManager;
  
  import demo.rmi.print.common.RemotePrinter;
  
  public class PrintClient {
  
      public static void main(String[] args) {
  
          System.setSecurityManager(new RMISecurityManager());
  
          try{
              RemotePrinter printer = (RemotePrinter) Naming.lookup("SERVER");
              printer.getPrinterStatus();
          }catch(Exception e){
              e.printStackTrace();
          }
  
      }
  
  }
  </code></pre>
  
  <p>I count on some good advice!</p>
  
  <p>Thanks in advance,</p>