title: RMI Binding Issue (from Windows RMI Server to Ubuntu RMI Registry)
body: <p>I have an RMI Server which correctly binds to an RMI Registry when running on localhost (to demonstrate that things are setup correctly). The code which does this is:</p>
  
  <pre><code> private void exposeTickHistoryRemoteProvider(TickHistoryRemoteInterface aTickHistoryServer) {
          if (System.getSecurityManager() == null) {
              SecurityManager mySecurityManager = getSecurityManager();
     System.setSecurityManager(mySecurityManager);
          }
    String rmiServerHostname = System.getProperties().getProperty("java.rmi.server.hostname");
    try {
     TickHistoryRemoteInterface stub =
                  (TickHistoryRemoteInterface) UnicastRemoteObject.exportObject(aTickHistoryServer, 0);
              Registry registry = LocateRegistry.getRegistry(rmiServerHostname);
              String[] services = registry.list();
              registry.rebind(RMI_SERVICENAME_REUTERS_TICKHISTORY_SERVER, stub);
              log.info(RMI_SERVICENAME_REUTERS_TICKHISTORY_SERVER + " bound");
          } catch (Exception e) {
           log.error(RMI_SERVICENAME_REUTERS_TICKHISTORY_SERVER + " exception:" + e.toString());
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>My localhost is running Windows with the following version of Java:</p>
  
  <pre><code>C:\eclipse&gt;java -version
  java version "1.6.0"
  Java(TM) SE Runtime Environment (build 1.6.0-b105)
  Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode)
  </code></pre>
  
  <p>Now, my issue is that I want to bind to an RMIRegistry running on a different machine (running Ubuntu 10.04, with OpenJDK IcedTea6 1.8.1, java version 1.6.0_18). </p>
  
  <p>On this Ubuntu machine, I have nothing in my CLASSPATH (echo $CLASSPATH), and am running the OpenJDK RMIRegistry (as opposed to the one bundled with Ubuntu): </p>
  
  <pre><code>sudo /usr/lib/jvm/java-6-openjdk/jre/bin/rmiregistry &amp;
  </code></pre>
  
  <p>Now, in the code above, when variable rmiServerHostname is "localhost" with the RMIRegistry running on my Windows localhost, the code works correctly (the RMI Server code binds to the RMI Registry). However, when rmiServerHostname is my remote Ubuntu machine ("deity") I get the following exception thrown on the "rebind" invocation:</p>
  
  <pre><code> java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
   java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
   java.lang.ClassNotFoundException: com.relative.tickhistory.provider.TickHistoryRemoteInterface
   java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
   java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
   java.lang.ClassNotFoundException: com.relative.tickhistory.provider.TickHistoryRemoteInterface
  </code></pre>
  
  <p>If I kill the RMIRegistry, I get a different error message (I would expect):</p>
  
  <pre><code> java.rmi.ConnectException: Connection refused to host: deity; nested exception is: 
   java.net.ConnectException: Connection refused: connect
   at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
   at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
   at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
   at sun.rmi.server.UnicastRef.newCall(Unknown Source)
   at sun.rmi.registry.RegistryImpl_Stub.list(Unknown Source)
  </code></pre>
  
  <p>I would assume there is no incompatibility between these implementations of RMIRegistry (Windows Java6 and Ubuntu OpenJDK 6)... but, I am unsure how to get to the bottom of this one. Especially because I know the code works correctly (in the first, Windows/localhost) example.</p>
  
  <hr>
  
  <h2>Progress So Far</h2>
  
  <p>Thanks alot for the helpful responses. I understand that I was getting confused between the rmiServerHostname (running on my localhost), and the rmiRegistryHostname (running on 'deity'). I have revised the code, with the following, but am still getting the same problem (note the change in the line "Registry registry = LocateRegistry.getRegistry(<strong>rmiRegistryHostname</strong>)"):</p>
  
  <pre><code>    String rmiServerCodebase = System.getProperties().getProperty("java.rmi.server.codebase");
      String rmiServerHostname = System.getProperties().getProperty("java.rmi.server.hostname");
      String rmiRegistryHostname = "deity";
      System.out.println("rmiServerCodebase=" + rmiServerCodebase + "; rmiServerHostname=" + rmiServerHostname);
      try {
          TickHistoryRemoteInterface stub =
              (TickHistoryRemoteInterface) UnicastRemoteObject.exportObject(aTickHistoryServer, 0);
          Registry registry = LocateRegistry.getRegistry(rmiRegistryHostname);
  </code></pre>
  
  <p>The output of the print statement is (note, my localhost is 'RTPC-16')</p>
  
  <pre><code>"rmiServerCodebase=file:///C:/workspace/DEV/ReutersTickHistoryServer/ReutersTickHistoryInterface.jar; rmiServerHostname=RTPC-16"
  </code></pre>
  
  <p>This file does exist:</p>
  
  <pre><code>C:\&gt;dir c:\workspace\DEV\ReutersTickHistoryServer\ReutersTickHistoryInterface.jar
   Volume in drive C is OS
   Volume Serial Number is 7AEB-A105
  
   Directory of c:\workspace\DEV\ReutersTickHistoryServer
  
  22/10/2010  12:21 PM             9,467 ReutersTickHistoryInterface.jar
                 1 File(s)          9,467 bytes
  </code></pre>
  
  <p>So, to summarise once more:</p>
  
  <ul>
  <li>This code works when RMIRegistry and RMIServer are on same physical host (eg, localhost)</li>
  <li>The problem occurs when I try to run <strong>only</strong> the RMIRegistry process on a separate host (ie, RMIRegistry is running on 'deity' as I want it to be whilst RMIServer is running on my localhost 'RTPC-16')</li>
  <li>I was bundling the RMI interface codebase ("ReutersTickHistoryInterface.jar") on both the client and server, so I was not anticipating RMI would need to transport any class definitions - RMI simply create the stub classes on the client and handle the actual RMI calls</li>
  </ul>