title: EJB Container initialization error, Error while binding JNDI name *** for EJB ***
body: <p>I am new to Java and I developed a sample Java EE application that works with normal Java client, but it does not work with Servlets. I developed EE project in Netbeans IDE with an Application Client, EJB module and Web module.</p>
  
  <p><strong>Customer.java</strong> <br></p>
  
  <pre><code>@Entity
  @Table(name = "customer")
  public class Customer implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @Column (name="id")
  private String id;
  @Column (name="name")
  private String name;
  
  public void setName(String name) {
      this.name = name;
  }
  
  public String getId() {
      return id;
  }
  
  public void setId(String id) {
      this.id = id;
  }
  </code></pre>
  
  <p><strong>myBeanInterface.java</strong></p>
  
  <pre><code>import Entities.Customer;
  import javax.ejb.Remote;
  @Remote
  public interface myBeanInterface {
      void addCustomer(Customer customer);    
  }
  </code></pre>
  
  <p><strong>CustomerSession.java</strong></p>
  
  <pre><code>@Stateless
  public class CustomerSession implements myBeanInterface {
  @PersistenceContext(unitName = "Omazon-EJBPU")
  EntityManager em;
  
  @Override
  public void addCustomer(Customer customer)
  {
      em.persist(customer);
  }
  </code></pre>
  
  <p><strong>Java Client</strong></p>
  
  <pre><code>@EJB
  private static myBeanInterface inter;
  public static void main(String[] args) throws NamingException {
  
      InitialContext context = new InitialContext();
      inter = (myBeanInterface) context.lookup("Session.myBeanInterface");
      Customer customer = new Customer();
      customer.setId("16906");
      customer.setName("My book from Main");
      inter.addCustomer(customer);
  }
  </code></pre>
  
  <p><strong>Servlet</strong></p>
  
  <pre><code>public class addCustomerServlet extends HttpServlet {
  
  @EJB
  public myBeanInterface myBean;
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException , NamingException {
  
  
      InitialContext context = new InitialContext();
  
      myBean = (myBeanInterface) context.lookup("Session.myBeanInterface");
      Customer customer = new Customer();
      customer.setId("1198");
      customer.setName("i1787");
      myBean.addCustomer(customer);
      response.setContentType("text/html;charset=UTF-8");
      try (PrintWriter out = response.getWriter()) {
          /* TODO output your page here. You may use following sample code. */
          out.println("&lt;!DOCTYPE html&gt;");
          out.println("&lt;html&gt;");
          out.println("&lt;head&gt;");
          out.println("&lt;title&gt;Servlet addCustomerServlet&lt;/title&gt;");            
          out.println("&lt;/head&gt;");
          out.println("&lt;body&gt;");
          out.println("&lt;h1&gt;Servlet addCustomerServlet at " + request.getContextPath() + "&lt;/h1&gt;");
          out.println("&lt;/body&gt;");
          out.println("&lt;/html&gt;");
      }
  }
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>INFO:   visiting unvisited references
  INFO:   visiting unvisited references
  INFO:   visiting unvisited references
  INFO:   visiting unvisited references
  INFO:   visiting unvisited references
  INFO:   EclipseLink, version: Eclipse Persistence Services - 2.5.0.v20130507-3faac2b
  INFO:   file:/C:/Users/Irfan/Documents/NetBeansProjects/TestWeb/build/web/WEB- INF/lib/Omazon-EJB.jar_Omazon-EJBPU login successful
  SEVERE:   Exception while invoking class org.glassfish.ejb.startup.EjbDeployer load method
  java.lang.RuntimeException: EJB Container initialization error
  at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:234)
  at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:291)
  at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:99)
  at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:206)
  at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:313)
  at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:493)
  at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
  at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
  at java.security.AccessController.doPrivileged(Native Method)
  at javax.security.auth.Subject.doAs(Subject.java:356)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
  at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
  at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
  at org.glassfish.grizzly.http.server.StaticHttpHandler.service(StaticHttpHandler.java:297)
  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)
  at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
  at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
  at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
  at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
  at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
  at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
  at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
  at java.lang.Thread.run(Thread.java:744)
  Caused by: java.lang.RuntimeException: Error while binding JNDI name Session.myBeanInterface for EJB CustomerSession
  at com.sun.ejb.containers.BaseContainer.initializeHome(BaseContainer.java:1552)
  at com.sun.ejb.containers.StatelessSessionContainer.initializeHome(StatelessSessionContainer.java:190)
  at com.sun.ejb.containers.StatelessContainerFactory.createContainer(StatelessContainerFactory.java:63)
  at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:221)
  ... 38 more
  Caused by: javax.naming.NameAlreadyBoundException: Use rebind to override
  at com.sun.enterprise.naming.impl.TransientContext.doBindOrRebind(TransientContext.java:322)
  at com.sun.enterprise.naming.impl.TransientContext.bind(TransientContext.java:257)
  at com.sun.enterprise.naming.impl.SerialContextProviderImpl.bind(SerialContextProviderImpl.java:85)
  at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.bind(LocalSerialContextProviderImpl.java:94)
  at com.sun.enterprise.naming.impl.SerialContext.bind(SerialContext.java:640)
  at com.sun.enterprise.naming.impl.SerialContext.bind(SerialContext.java:657)
  at javax.naming.InitialContext.bind(InitialContext.java:423)
  at javax.naming.InitialContext.bind(InitialContext.java:423)
  at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:212)
  at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:196)
  at com.sun.ejb.containers.BaseContainer$JndiInfo.publish(BaseContainer.java:4859)
  at com.sun.ejb.containers.BaseContainer.initializeHome(BaseContainer.java:1539)
  ... 41 more
  
  SEVERE:   Exception during lifecycle processing
  java.lang.RuntimeException: EJB Container initialization error
  at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:234)
  at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:291)
  at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:99)
  at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:206)
  at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:313)
  at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:493)
  at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
  at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
  at java.security.AccessController.doPrivileged(Native Method)
  at javax.security.auth.Subject.doAs(Subject.java:356)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
  at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
  at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
  at org.glassfish.grizzly.http.server.StaticHttpHandler.service(StaticHttpHandler.java:297)
  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)
  at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
  at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
  at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
  at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
  at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
  at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
  at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
  at java.lang.Thread.run(Thread.java:744)
  Caused by: java.lang.RuntimeException: Error while binding JNDI name Session.myBeanInterface for EJB CustomerSession
  at com.sun.ejb.containers.BaseContainer.initializeHome(BaseContainer.java:1552)
  at com.sun.ejb.containers.StatelessSessionContainer.initializeHome(StatelessSessionContainer.java:190)
  at com.sun.ejb.containers.StatelessContainerFactory.createContainer(StatelessContainerFactory.java:63)
  at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:221)
  ... 38 more
  Caused by: javax.naming.NameAlreadyBoundException: Use rebind to override
  at com.sun.enterprise.naming.impl.TransientContext.doBindOrRebind(TransientContext.java:322)
  at com.sun.enterprise.naming.impl.TransientContext.bind(TransientContext.java:257)
  at com.sun.enterprise.naming.impl.SerialContextProviderImpl.bind(SerialContextProviderImpl.java:85)
  at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.bind(LocalSerialContextProviderImpl.java:94)
  at com.sun.enterprise.naming.impl.SerialContext.bind(SerialContext.java:640)
  at com.sun.enterprise.naming.impl.SerialContext.bind(SerialContext.java:657)
  at javax.naming.InitialContext.bind(InitialContext.java:423)
  at javax.naming.InitialContext.bind(InitialContext.java:423)
  at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:212)
  at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:196)
  at com.sun.ejb.containers.BaseContainer$JndiInfo.publish(BaseContainer.java:4859)
  at com.sun.ejb.containers.BaseContainer.initializeHome(BaseContainer.java:1539)
  ... 41 more
  
  SEVERE:   Exception while loading the app
  SEVERE:   The web application [unknown] created a ThreadLocal with key of type [org.glassfish.pfl.dynamic.codegen.impl.CurrentClassLoader$1] (value [org.glassfish.pfl.dynamic.codegen.impl.CurrentClassLoader$1@2aa5b721]) and a value of type [org.glassfish.web.loader.WebappClassLoader] (value [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
  INFO:   file:/C:/Users/Documents/NetBeansProjects/TestWeb/build/web/WEB-INF/lib/Omazon-EJB.jar_Omazon-EJBPU logout successful
  SEVERE:   Exception while loading the app : EJB Container initialization error
  java.lang.RuntimeException: Error while binding JNDI name Session.myBeanInterface for EJB CustomerSession
  at com.sun.ejb.containers.BaseContainer.initializeHome(BaseContainer.java:1552)
  at com.sun.ejb.containers.StatelessSessionContainer.initializeHome(StatelessSessionContainer.java:190)
  at com.sun.ejb.containers.StatelessContainerFactory.createContainer(StatelessContainerFactory.java:63)
  at org.glassfish.ejb.startup.EjbApplication.loadContainers(EjbApplication.java:221)
  at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:291)
  at org.glassfish.ejb.startup.EjbDeployer.load(EjbDeployer.java:99)
  at org.glassfish.internal.data.ModuleInfo.load(ModuleInfo.java:206)
  at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:313)
  at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:493)
  at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
  at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
  at java.security.AccessController.doPrivileged(Native Method)
  at javax.security.auth.Subject.doAs(Subject.java:356)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
  at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
  at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
  at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
  at org.glassfish.grizzly.http.server.StaticHttpHandler.service(StaticHttpHandler.java:297)
  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)
  at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
  at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
  at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
  at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
  at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
  at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
  at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
  at java.lang.Thread.run(Thread.java:744)
  Caused by: javax.naming.NameAlreadyBoundException: Use rebind to override
  at com.sun.enterprise.naming.impl.TransientContext.doBindOrRebind(TransientContext.java:322)
  at com.sun.enterprise.naming.impl.TransientContext.bind(TransientContext.java:257)
  at com.sun.enterprise.naming.impl.SerialContextProviderImpl.bind(SerialContextProviderImpl.java:85)
  at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.bind(LocalSerialContextProviderImpl.java:94)
  at com.sun.enterprise.naming.impl.SerialContext.bind(SerialContext.java:640)
  at com.sun.enterprise.naming.impl.SerialContext.bind(SerialContext.java:657)
  at javax.naming.InitialContext.bind(InitialContext.java:423)
  at javax.naming.InitialContext.bind(InitialContext.java:423)
  at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:212)
  at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.publishObject(GlassfishNamingManagerImpl.java:196)
  at com.sun.ejb.containers.BaseContainer$JndiInfo.publish(BaseContainer.java:4859)
  at com.sun.ejb.containers.BaseContainer.initializeHome(BaseContainer.java:1539)
  ... 41 more
  </code></pre>