title: EJB3 Glassfish JNDI lookup
body: <p>I am using Glassfish-bundled Eclipse IDE. I wrote a simple EJB application. but it doesn't work. </p>
  
  <pre><code>@Stateless
  @Remote(CalculatorRemote.class) 
  @Local(CalculatorLocal.class) 
  public class Calculator implements CalculatorRemote, CalculatorLocal {
      @Override
      public String sayHello(String name) {
          System.out.println("ejb:"+name);
          return null;
      }
  }
  
  ----
  
  @Remote
  public interface CalculatorRemote {
      public String sayHello(String name);
  
  }
  -------
  
  @Local
  public interface CalculatorLocal {
      public String sayHello(String name);
  }
  </code></pre>
  
  <p>I wrote a standalone client to test, but failed. can't find JNDI.</p>
  
  <pre><code>public class Main {
  
      public static void main(String[] args) throws Exception {        
          InitialContext ctx = new InitialContext();      
          CalculatorRemote bean = (CalculatorRemote) ctx.lookup("java:global/TestEAR/TEjb/Calculator!com.CalculatorRemote");
          bean.sayHello("Billy Bob");
  
      }
  
  }
  </code></pre>
  
  <p>In the server log, it said</p>
  
  <pre><code>INFO: Portable JNDI names for EJB Calculator : [java:global/TestEAR/TEjb/Calculator!com.CalculatorRemote, java:global/TestEAR/TEjb/Calculator!com.CalculatorLocal]
  INFO: Glassfish-specific (Non-portable) JNDI names for EJB Calculator : [com.CalculatorRemote, com.CalculatorRemote#com.CalculatorRemote]
  </code></pre>
  
  <p>Also, I have tried  </p>
  
  <pre><code>ctx.lookup("com.CalculatorRemote")
  </code></pre>
  
  <p>still doesn't work. </p>
  
  <p>error message is</p>
  
  <pre><code>java.lang.NullPointerException
      at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
      at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
      at javax.naming.InitialContext.lookup(InitialContext.java:392)
      at com.Main.main(Main.java:9)
  Exception in thread "main" javax.naming.NamingException: Lookup failed for 'java:global/TestEAR/TEjb/Calculator!com.CalculatorRemote' in SerialContext  [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext  [Root exception is java.lang.NullPointerException]]
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
      at javax.naming.InitialContext.lookup(InitialContext.java:392)
      at com.Main.main(Main.java:9)
  Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext  [Root exception is java.lang.NullPointerException]
      at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
      ... 2 more
  Caused by: java.lang.NullPointerException
      at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
      at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
      ... 3 more
  </code></pre>
  
  <p>Please help me. </p>