title: EJB injection - JNDI lookup fails
body: <p>So I'm starting to develop a Java EE Enterprise Application with Netbeans 8.2. It's about a shop, where you have a shopping cart and you have to store each client's session correctly.</p>
  
  <p>In NetBeans I have: <code>Shop-ejb</code> and <code>Shop-war</code>. </p>
  
  <p><code>Shop-ejb</code> contains the following classes:</p>
  
  <ul>
  <li><p><code>CartLocal.java</code></p>
  
  <pre><code>package cart;
  
  @Local
  public interface CartLocal{
  }
  </code></pre></li>
  <li><p><code>CartBean.java</code></p>
  
  <pre><code>package cart;
  
  @Stateful
  @StatefulTimeout(unit = TimeUnit.MINUTES, value = 20)
  public class CartBean implements CartLocal{
  }
  </code></pre></li>
  </ul>
  
  <p>Then, <code>Shop-war</code> contains the following servlet:</p>
  
  <ul>
  <li><p><code>Servlet.java</code></p>
  
  <pre><code>import cart.CartLocal;
  import java.io.*;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.servlet.*;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.*;
  
  @WebServlet(name = "Servlet", urlPatterns = {"/Servlet"})
  public class Servlet extends HttpServlet {
  
  private static final String CARRITO_SESSION_KEY = "shoppingCart";
  
  public Servlet() {
      super();
  }
  
  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
      CartLocal carrito = (CartLocal) request.getSession().getAttribute(CARRITO_SESSION_KEY);
  
      try {
          if (carrito == null) {
              InitialContext ic = new InitialContext();
              carrito = (CartLocal) ic.lookup("java:global/Shop/Shop-ejb/CartBean!cart.CartLocal");
  
              request.getSession().setAttribute(CARRITO_SESSION_KEY, carrito);
          }
      } catch (NamingException ex) {
          Logger.getLogger(Servlet.class.getName()).log(Level.SEVERE, null, ex);
      }
  }
  </code></pre></li>
  </ul>
  
  <p>I'm using GlasshFish, and when I access to <code>http://localhost:8080/Shop-war/Servlet</code> I get the following error on the NetBeans console:</p>
  
  <pre><code>Grave:   javax.naming.NamingException: Lookup failed for 'java:global/Shop/Shop-ejb/CartBean!cart.CartLocal' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: Shop]
  </code></pre>
  
  <p>I know the <code>lookup</code> is failing but I tried multiple things, without result. Hope you can help me.</p>