title: javax.naming.NameNotFoundException while ejb lookup
body: <p>I am migrating one ejb application from weblogic to jboss. The application is looking for ejb using jndi. I have ejb-jar.xml and jboss.xml into WEB-INF/ as below </p>
  
  <p>jboss.xml</p>
  
  <pre><code>&lt;!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN"
     "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd"&gt;
  
  &lt;jboss&gt;
      &lt;enterprise-beans&gt;
          &lt;session&gt;
              &lt;ejb-name&gt;DataAccessEJB&lt;/ejb-name&gt;
              &lt;jndi-name&gt;HeatMapDataAccessJNDI&lt;/jndi-name&gt;
              &lt;local-jndi-name&gt;HeatMapDataAccessLocalJNDI&lt;/local-jndi-name&gt;
          &lt;/session&gt;
          &lt;session&gt;
              &lt;ejb-name&gt;PMSessionFacadeEJB&lt;/ejb-name&gt;
              &lt;jndi-name&gt;PMSessionFacadeJNDI&lt;/jndi-name&gt;
              &lt;local-jndi-name&gt;PMSessionFacadeLocalJNDI&lt;/local-jndi-name&gt;
          &lt;/session&gt;
          &lt;session&gt;
              &lt;ejb-name&gt;RRMSessionFacadeEJB&lt;/ejb-name&gt;
              &lt;jndi-name&gt;RRMSessionFacadeJNDI&lt;/jndi-name&gt;
              &lt;local-jndi-name&gt;RRMSessionFacadeLocalJNDI&lt;/local-jndi-name&gt;
          &lt;/session&gt;
          &lt;session&gt;
              &lt;ejb-name&gt;FIPMSessionFacadeEJB&lt;/ejb-name&gt;
              &lt;jndi-name&gt;FIPMSessionFacadeJNDI&lt;/jndi-name&gt;
              &lt;local-jndi-name&gt;FIPMSessionFacadeLocalJNDI&lt;/local-jndi-name&gt;
          &lt;/session&gt;              
      &lt;/enterprise-beans&gt;
  &lt;/jboss&gt;
  </code></pre>
  
  <p>ejb-jar.xml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE ejb-jar PUBLIC
  "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
  "http://java.sun.com/dtd/ejb-jar_2_0.dtd"&gt;
  &lt;ejb-jar&gt;
      &lt;enterprise-beans&gt;
      &lt;!-- A list of all the session and entity beans packaged within this jar file. --&gt;
          &lt;session&gt;
              &lt;!-- An arbitrary identifier that's used to match up this description of the bean with the
           corresponding entry in the weblogic-ejb-jar.xml file --&gt;
              &lt;ejb-name&gt;
          DataAccessEJB
              &lt;/ejb-name&gt;
  
              &lt;!-- The name of the interface implemented by the bean's home object --&gt;
              &lt;home&gt;
          com.bfm.app.pirptfe.heatmap.ejb.DataAccessHomeInterface
              &lt;/home&gt;
  
              &lt;!-- The name of the interface implemented by the bean's remote object --&gt;
              &lt;remote&gt;
          com.bfm.app.pirptfe.heatmap.ejb.DataAccessRemoteInterface
              &lt;/remote&gt;
              &lt;local-home&gt;
                  com.bfm.app.pirptfe.heatmap.ejb.DataAccessLocalHomeInterface
              &lt;/local-home&gt;
              &lt;local&gt;
                  com.bfm.app.pirptfe.heatmap.ejb.DataAccessLocalInterface
              &lt;/local&gt;
              &lt;!-- The name of the bean class --&gt;
              &lt;ejb-class&gt;
          com.bfm.app.pirptfe.heatmap.ejb.DataAccessBean
              &lt;/ejb-class&gt;
  
              &lt;!-- Is this session bean Stateful or Stateless? --&gt;
              &lt;session-type&gt;
          Stateless
              &lt;/session-type&gt;
  
              &lt;!-- If this bean uses any transactions, will these transactions be managed by the Container or
           by the Bean itself? --&gt;
              &lt;transaction-type&gt;
          Container
              &lt;/transaction-type&gt;
      &lt;/session&gt;
  
          &lt;session&gt;
              &lt;ejb-name&gt;
          PMSessionFacadeEJB
              &lt;/ejb-name&gt;
              &lt;home&gt;
          com.bfm.app.pirptfe.heatmap.ejb.PMSessionFacadeHome
              &lt;/home&gt;
              &lt;remote&gt;
          com.bfm.app.pirptfe.heatmap.ejb.PMSessionFacadeRemote
              &lt;/remote&gt;
              &lt;ejb-class&gt;
          com.bfm.app.pirptfe.heatmap.ejb.PMSessionFacadeBean
              &lt;/ejb-class&gt;
              &lt;session-type&gt;
          Stateless
              &lt;/session-type&gt;
              &lt;transaction-type&gt;
          Container
              &lt;/transaction-type&gt;     
          &lt;/session&gt;
          &lt;session&gt;
              &lt;ejb-name&gt;
          RRMSessionFacadeEJB
              &lt;/ejb-name&gt;
              &lt;home&gt;
          com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeHome
              &lt;/home&gt;
              &lt;remote&gt;
          com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeRemote
              &lt;/remote&gt;
              &lt;ejb-class&gt;
          com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeBean
              &lt;/ejb-class&gt;
              &lt;session-type&gt;
          Stateless
              &lt;/session-type&gt;
              &lt;transaction-type&gt;
          Container
              &lt;/transaction-type&gt;     
          &lt;/session&gt;     
          &lt;session&gt;
              &lt;ejb-name&gt;
          FIPMSessionFacadeEJB
              &lt;/ejb-name&gt;
              &lt;home&gt;
          com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeHome
              &lt;/home&gt;
              &lt;remote&gt;
          com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeRemote
              &lt;/remote&gt;
              &lt;ejb-class&gt;
          com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeBean
              &lt;/ejb-class&gt;
              &lt;session-type&gt;
          Stateless
              &lt;/session-type&gt;
              &lt;transaction-type&gt;
          Container
              &lt;/transaction-type&gt;     
          &lt;/session&gt;   
      &lt;/enterprise-beans&gt;
  &lt;/ejb-jar&gt;
  </code></pre>
  
  <p>When i run my application it load. log shown below </p>
  
  <pre><code>14:08:16,990 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named FIPMSessionFacadeEJB in deployment unit deployment "pirptfe.war" are as follows:
  
      java:global/pirptfe/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeRemote
      java:app/pirptfe/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeRemote
      java:module/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeRemote
      java:jboss/exported/pirptfe/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeRemote
      java:global/pirptfe/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeHome
      java:app/pirptfe/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeHome
      java:module/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeHome
      java:jboss/exported/pirptfe/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeHome
  </code></pre>
  
  <p>The JNDI name used to lookup a service is as below in my code</p>
  
  <pre><code>// The JNDI Names used to lookup a service
  private static final String PMSESSIONFACADEEJB_JNDIHOME   =
          "PMSessionFacadeJNDI";
  private static final String RRMSESSIONFACADEEJB_JNDIHOME  =
          "RRMSessionFacadeJNDI";
  private static final String FIPMSESSIONFACADEEJB_JNDIHOME =
          "FIPMSessionFacadeJNDI";
  </code></pre>
  
  <p>When code is trying to lookup for ejb in context using below code, it give exception </p>
  
  <p>serviceName is JNDI name in below code</p>
  
  <pre><code>public EJBHome getEJBHome(int parServiceId)
                     throws FrontServiceLocatorException {
  
      // Trying to find the JNDI Name for the reqested service
      String  serviceName = getServiceName(parServiceId);
      EJBHome ejbHome = null;
      try {
  
          // Checking to see if I can find the EJBHome interface in the cache
          if (ejbHomeCashe_.containsKey(serviceName)) {
              ejbHome = (EJBHome)ejbHomeCashe_.get(serviceName);
              return ejbHome;
          } else {
  
              // I could not find the home interface in the cache, look it up
              // and then cache it
              Context ctx         = new InitialContext();
              Object  jndiRef     = ctx.lookup(serviceName);
              Object  portableObj = PortableRemoteObject.narrow(jndiRef,
                                                                getEJBHomeRef(
                                                                        parServiceId));
              ejbHome = (EJBHome)portableObj;
              ejbHomeCashe_.put(serviceName, ejbHome);
              return ejbHome;
          }
      } catch (NamingException e) {
          throw new FrontServiceLocatorException("Naming exception error in FrontServiceLocator.getEJBHome()",
                                                 e);
      }
       catch (Exception e) {
          throw new FrontServiceLocatorException("General exception in FrontServiceLocator.getEJBHome()",
                                                 e);
      }
  }
  </code></pre>
  
  <p>Exception : </p>
  
  <pre><code>18:40:12,376 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) javax.naming.NameNotFoundException: RRMSessionFacadeJNDI -- service jboss.naming.context.java.RRMSessionFacadeJNDI
  
  18:40:12,376 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
  
  18:40:12,392 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
  
  18:40:12,392 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:113)
  
  18:40:12,392 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
  
  18:40:12,407 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at javax.naming.InitialContext.lookup(InitialContext.java:411)
  
  18:40:12,407 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at com.bfm.app.pirptfe.heatmap.web.FrontServiceLocator.getEJBHome(FrontServiceLocator.java:191)
  
  18:40:12,407 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at com.bfm.app.pirptfe.heatmap.web.CommonalityRRM.process(CommonalityRRM.java:77)
  
  18:40:12,423 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at com.bfm.app.pirptfe.heatmap.web.CommonalityRRM.doPost(CommonalityRRM.java:54)
  
  18:40:12,423 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
  </code></pre>
  
  <p>Could someone help me to get it solve.</p>