title: JNDI lookup of EJB3 inside an EAR file on Glassfish
body: <p>I have an EAR file with a bunch of JARs in it, and one of these JARs contains Local Session Beans (EJB3). I need to perform a JNDI lookup of these Session Beans from within an unmanaged POJO, also contained in the EAR (and in this case in the same JAR as the EJBs as well). I tried following the <a href="https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#POJOLocalEJB" rel="nofollow noreferrer">Glassfish EJB FAQ</a>, but I keep on receiving a javax.naming.NameNotFoundException no matter what I try.</p>
  
  <p>I am unsure of a few things. Where should I put my ejb-jar.xml (I tried the EARs META-INF as well as the JARs META-INF)? Do I need a sun-ejb-jar.xml? What exactly is ejb-link, what does it do? What could I be doing wrong (my configuration is almost identical to the one given in the FAQ for local lookups)?</p>
  
  <p>I list some of the configuration I tried and the result below:</p>
  
  <pre><code>&lt;enterprise-beans&gt;
    &lt;session&gt;
      &lt;ejb-name&gt;ITestBean&lt;/ejb-name&gt;
      &lt;ejb-class&gt;com.test.TestBean&lt;/ejb-class&gt;
      &lt;ejb-local-ref&gt;
        &lt;ejb-ref-name&gt;ITestBean&lt;/ejb-ref-name&gt;
        &lt;local&gt;com.test.ITestBean&lt;/local&gt;
      &lt;/ejb-local-ref&gt;
    &lt;/session&gt;
   &lt;/enterprise-beans&gt;
  </code></pre>
  
  <p><em>Application deploys but JNDI lookup returns null.</em></p>
  
  <pre><code>&lt;enterprise-beans&gt;
    &lt;session&gt;
      &lt;ejb-name&gt;ITestBean&lt;/ejb-name&gt;
      &lt;ejb-class&gt;com.test.TestBean&lt;/ejb-class&gt;
      &lt;ejb-local-ref&gt;
        &lt;ejb-ref-name&gt;ITestBean&lt;/ejb-ref-name&gt;
        &lt;local&gt;com.test.ITestBean&lt;/local&gt;
        &lt;ejb-link&gt;ITestBean&lt;/ejb-link&gt;
      &lt;/ejb-local-ref&gt;
    &lt;/session&gt;
   &lt;/enterprise-beans&gt;
  </code></pre>
  
  <p><em>Application doesn't deploy: Unable to determine local  business vs. remote business designation for  EJB 3.0 ref Unresolved Ejb-Ref ITestBean@jndi.</em></p>
  
  <pre><code>&lt;enterprise-beans&gt;
    &lt;session&gt;
      &lt;ejb-name&gt;ITestBean&lt;/ejb-name&gt;
      &lt;ejb-class&gt;com.test.TestBean&lt;/ejb-class&gt;
      &lt;ejb-local-ref&gt;
        &lt;ejb-ref-name&gt;ITestBean&lt;/ejb-ref-name&gt;
        &lt;local&gt;com.test.ITestBean&lt;/local&gt;
        &lt;ejb-link&gt;MyJar.jar#ITestBean&lt;/ejb-link&gt;
      &lt;/ejb-local-ref&gt;
    &lt;/session&gt;
   &lt;/enterprise-beans&gt;
  </code></pre>
  
  <p><em>Application doesn't deploy: Error: Unresolved : MyJar.jar#ITestBean.</em></p>
  
  <pre><code>&lt;enterprise-beans&gt;
    &lt;session&gt;
      &lt;ejb-name&gt;ITestBean&lt;/ejb-name&gt;
      &lt;local&gt;com.test.ITestBean&lt;/local&gt;
      &lt;ejb-local-ref&gt;
        &lt;ejb-ref-name&gt;ITestBean&lt;/ejb-ref-name&gt;
      &lt;/ejb-local-ref&gt;
    &lt;/session&gt;
   &lt;/enterprise-beans&gt;
  </code></pre>
  
  <p><em>Error processing EjbDescriptor</em></p>