title: access a Local Session Bean from another EAR?
body: <p>How can I call a Local Session Bean inside an EAR from another EAR, both 
  deployed in the same Glassfish v3 domain?</p>
  
  <p>This is the structure:</p>
  
  <p></p>
  
  <pre><code>Glassfish v3 Domain1
  
      EAR1
              EAR1-EJB.jar
                      class TestSessionBean           &lt;-- @Stateless
              common.jar
                      interface TestSessionLocal      &lt;-- @Local
  
      EAR2
              EAR2-EJB.jar
                      class TestSessionBeanClient     &lt;-- @Singleton, @LocalBean
              common.jar
                      interface TestSessionLocal      &lt;-- @Local
  </code></pre>
  
  <p>
  TestSessionBean implements TestSessionLocal, boths EARs has common.jar.</p>
  
  <p>I need to use TestSessionBean from TestSessionBeanClient. I would like to take 
  advantage of local session bean because of performance.</p>
  
  <p>I know I can't use a simple @EJB call in the TestSessionBeanClient, so I tried 
  to lookup like this:</p>
  
  <pre><code>InitialContext ic = new InitialContext();
  TestSessionLocal tsl = ic.lookup("java:global/EAR1/EAR1-EJB/TestSessionBean!org.test.TestSessionLocal");
  </code></pre>
  
  <p>That will throw a ClassCastException because the returned object will not be 
  TestSessionLocal but a proxy class like:</p>
  
  <pre><code>TestSessionLocal_1389930137
  </code></pre>
  
  <p>that to be able to call its methos I must do reflection to find its methods.</p>
  
  <p>Please help.</p>
  
  <p>Thank you in advance.</p>