4 Replies Latest reply on Jul 25, 2012 1:02 PM by Julio Faerman

    EJB lookup without java:comp/env/

    Julio Faerman Novice



      I am migrating a large app to JBoss AS7 where all JNDI lookups (EJB 2) are not prefixed by java:comp/env/


      I have mapped the ejb-ref in web.xml so that i can sucessfully lookup names like this:




      But i can not change the app and all the lookups are like  initialContext.lookup("ejb/MyBean");


      Is it possible to have the java:comp/env/ as a default or any other trick to make this lookup succeeed?

        • 1. Re: EJB lookup without java:comp/env/
          Jay SenSharma Master

          Hi Julio,


                    In "Standalone-full.xml"  you can map the JNDI name to "java:comp/env/ejb/MyBean" as following:


                  <subsystem xmlns="urn:jboss:domain:naming:1.2">


                             <lookup name="java:global/ejb/MyBean" lookup="java:global/EJB2Demo/MySessionBean!ejb2.demo.InterestCalculatorHome"/>






          In   "web.xml" of your applicationyou can use <ejb-ref> as following:









          And your JSP lookup code will look like following:


          <%@ page import="java.util.*,javax.ejb.*,javax.naming.*,javax.rmi.*" %>


                       String jndiName = "java:comp/env/ejb/MyBean";


                       Context ic = new InitialContext();

                       System.out.println("\n\t Inside index.jsp About to look up jndi name " + jndiName);

                       Object obj = ic.lookup(jndiName);

                       System.out.println("\n\tlookup returned " + obj);


                       ejb2.demo.InterestCalculatorHome home=(ejb2.demo.InterestCalculatorHome)obj;

                       ejb2.demo.InterestCalculatorRemote remote=(ejb2.demo.InterestCalculatorRemote)home.create();

                       System.out.println("\n\tremote.calculateInterest(10.0,20f,30)=  "+remote.calculateInterest(10.0,20f,30));

                       System.out.println("\n\tremote.calculateInterest(10.0,20f,30)=  "+remote.calculateInterest(10.0,20f,30));


          • 2. Re: EJB lookup without java:comp/env/
            Stephen Coy Master

            Julio Faerman wrote:


            ... all JNDI lookups (EJB 2) are not prefixed by java:comp/env/



            This means your application was never portable. If you want to run in JBoss AS 7.x I don't think you will have any choice. You must change the lookup names in your code.

            • 3. Re: EJB lookup without java:comp/env/
              Jay SenSharma Master

              EJB 2.0 added local interfaces that do not use RMI call by value semantics. These interfaces use a call by reference semantic and therefore do not incur any RMI serialization overhead. An EJB local reference is a link in an application component naming environment that points to a deployed EJB local home interface. The name used by the application component is a logical link that isolates the component from the actual name of the EJB local home in the deployment environment. The J2EE specification recommends that all references to enterprise beans be organized in the java:comp/env/ejb context of the application component's environment.


              An <ejb-ref-name> element that specifies the name of the reference relative to the java:comp/env context. To place the reference under the recommended java:comp/env/ejb context, use an ejb/link-name form for the ejb-ref-name value.

              • 4. Re: EJB lookup without java:comp/env/
                Julio Faerman Novice

                I wish it was my code to change

                I know it is not standard and portable, but unfortunately this clients current AS (OAS) and other prospects (Weblogic) seems to handle it.