title: Java RMI Registry from within Jar file
body: <p>I have a problem involving RMI Registry creation and obtention within the scope of a distributed processing tool. First of all, I will describe briefly my environment:</p>
  
  <p><strong>ENVIRONMENT</strong><br>
  I need a background Java process to be executed permanently. The instances of my software (in the same physical machine) need to communicate with that process in order to perform some operations. The solution I found months ago to communicate different JVM's on the same physical machine was Java RMI. So, I launch the background process and create a Registry from it:</p>
  
  <pre><code>    CAEATServiceManagerInterface smi = (CAEATServiceManagerInterface)UnicastRemoteObject.exportObject(csm, 0);
      Registry registry = LocateRegistry.createRegistry(8090);            
      registry.rebind("ServiceManager", smi);
  </code></pre>
  
  <p>Notes: <em>csm</em> is the Remote object to be exported. Security policy has been properly installed (AllPermission for everybody) and so has been the RMISecurityManager.</p>
  
  <p>For now on, instances of my main program are able to Lookup the Registry and obtain the Remote object at any given moment:</p>
  
  <pre><code>    Registry registry = LocateRegistry.getRegistry(8090);
      smi = (CAEATServiceManagerInterface)registry.lookup("ServiceManager");
  </code></pre>
  
  <p><strong>PROBLEM</strong><br>
  The problem arises when my program (both the main program that obtains the Registry and the background program that creates it) is executed from within a jar file. If they're executed from Eclipse, everything works fine. If they are executed directly from command-line, it is also OK. But when they are packed into an auto-executable jar file for distribution, the background process seems to create the Registry fine, but when the main program tries to Lookup it, this happens:</p>
  
  <pre><code>java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
      java.io.EOFException
      at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
      at sener.caeat.autoejecutable.PublicadorStandalone.getServiceManagerInterface(PublicadorStandalone.java:170)
      at sener.caeat.autoejecutable.PublicadorStandalone.publicarEsquema(PublicadorStandalone.java:319)    
      at sener.caeat.autoejecutable.CargadorStandalone.mostrarDialogoOpcionesPublicacion(CargadorStandalone.java:415)
      at sener.caeat.autoejecutable.ExtractorJars.main(ExtractorJars.java:32)
  Caused by: java.io.EOFException
      at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2553)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1296)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
      at sun.rmi.server.MarshalInputStream.readLocation(MarshalInputStream.java:285)
      at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalInputStream.java:228)
      at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1530)
      at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1492)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
      ... 5 more
  </code></pre>
  
  <p>Forget about my classes, what I don't understand is the EOFException... Why is it only launched when the program is executed from within a jar?</p>
  
  <p><em>Aditional data</em>: if the background program is launched from within the jar file, but the main program that Lookups the Registry is launched from Eclipse, the probles is still there.</p>
  
  <p>Thanks in advance.</p>