title: Glassfish 3/EJB 3. Standalone java client
body: <p>i'm developing an application on top of netbeans API using Glassfish 3.1.2. My netbeans application is supposed to be my standalone java client that have to connect to the EJB.</p>
  
  <p>I have packaged my EJB into an EAR (enterprise application). The problem i'm facing of is that i got an exception when i try to lookup for available EJBs.</p>
  
  <p>Here is my bean session:</p>
  
  <pre><code>@Stateless
  @EJB(name = "java:global/AltServer", beanInterface = AltServerRemote.class)
  public class AltServer implements AltServerRemote {
  </code></pre>
  
  <p>The remote interface:</p>
  
  <pre><code>@Remote
  public interface AltServerRemote {
  </code></pre>
  
  <p>And finally the lookup call:</p>
  
  <pre><code>props.setProperty("org.omg.CORBA.ORBInitialHost", getGlassfishHostname());
  props.setProperty("org.omg.CORBA.ORBInitialPort", getServerPort());
  ctx = new InitialContext(props)
  
  ctx.lookup("java:global/AltServerEnt/AltServer-ejb/AltServer")
  </code></pre>
  
  <p>About how to lookup an EJB packaged into an EAR, i have followed this : <a href="http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#CosNaming" rel="nofollow">http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#CosNaming</a> and foud the jndi syntax: </p>
  
  <pre><code>java:global[/&lt;app-name&gt;]/&lt;module-name&gt;/&lt;bean-name&gt;
  </code></pre>
  
  <p>So in my case my enterprise application is <strong>AltServerEnt</strong>, my EJB module is <strong>AltServer-ejb</strong> and my session bean is called <strong>AltServer</strong> (see above).</p>
  
  <p>Note: I have used the @EJB annotation to my session bean to specify a name like explained in FAQ i linked above, i'm not sure it's suitable when the EJB is part of an EAR. Anyone know?</p>
  
  <p>And here the exception i got, raised at the line of the lookup:</p>
  
  <pre><code>java.lang.ClassNotFoundException: com.sun.ejb.codegen.GenericEJBHome_Generated
  </code></pre>
  
  <p>There are a lot of "Caused" clauses but here is the first one:</p>
  
  <pre><code>javax.naming.NamingException: Lookup failed for 'java:global/AltServerEnt/AltServer-ejb/AltServer' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=127.0.0.1, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: ejb ref resolution error for remote business interfaceorg.altanis.remote.AltServerRemote [Root exception is java.lang.RuntimeException: Could not invoke defineClass!]]
  </code></pre>
  
  <p>So i guess my session bean is not found but why? My JNDI syntax isn't right?</p>
  
  <p>EDIT: Just to notice my project organization:</p>
  
  <ul>
  <li>AltServerEnt: Enterprise Application - contains the EJB module</li>
  <li>AltServer-ejb: EJB Module - contains the sessions bean and includes a netbeans plugin that contains the remote interface (AltServerRemote).</li>
  </ul>
  
  <p>Thanks for reading.</p>