5 Replies Latest reply: Oct 7, 2011 9:15 AM by Robert.Patrick-Oracle RSS

    Is java:comp/env automatically prefixed ?

      I am developing some enterprise apps with EJB3 on WebLogic 10.3.5.
      An EJB in EAR A must call remote methods on an EJB in EAR B. Both EARs are deployed on the same server.
      I have arranged all XML descriptors according to specs and practices.

      The problem is looking up the remote EJB: if I use the standard jndi key,


      I get a NameNotFoundException at runtime as soon as I call InitialContext()::lookup().

      On the other hand, I f I use the short key


      everything runs OK.

      To preserve application server portability (eg to Glassfish) I want to be able to query the JNDI tree with the full form "java:comp/env/ejb/MyBean".
      How can I configure Weblogic to stop setting the prefix atomatically ?

        • 1. Re: Is java:comp/env automatically prefixed ?
          java:comp/env is the local, context-sensitive JNDI namespace for a particular Java EE component. I suspect the reason it works when you use "ejb/MyBean" is because the global JNDI name of the other EJB is set to ejb/MyBean.

          To use java:comp/env/ejb/MyBean to lookup another EJB in another application, you must map the other EJB into the local EJB's context-sensitive JNDI namespace. Using a deployment descriptor, you would add the following in the local EJB's ejb-jar.xml:


          and then add the following in local EJB's weblogic-ejb-jar.xml:

          <jndi-name>ejb/MyBean</jndi-name> <!-- Note that this must map to the global JNDI name specified by the other EJB -->

          Hope this helps,
          • 2. Re: Is java:comp/env automatically prefixed ?
            Thanks for replying, but that's exactly how I had set things up in deployment descriptors...I checked them a thousand times and everything looks OK, that's why I thought about some specific WLS prepending and decided to post here.
            Still a mystery to me.

            In the meanwhile I worked around this by implementing a "two-phase" lookup, eg

            try {
            lookup("java:comp/env/ejb/MyBean") ;
            } catch (NameNotFoundException xc) {
            try {
            lookup("java:comp/env/ejb/MyBean") ;
            } catch (NameNotFoundException xc1) {
            throw fatal ;

            Running in Glassfish the first lookup is successful, running in WLS it falls back on the second.


            Edited by: user6780872 on 7-ott-2011 5.14
            • 3. Re: Is java:comp/env automatically prefixed ?
              If you did what I recommended and it is still failing, please open an SR with Oracle Support and upload a test case. If you send me the SR number, I will take a look myself...
              • 4. Re: Is java:comp/env automatically prefixed ?
                Well, I do have a test case, but the WebLogic licensee is my Client, not me. I wonder if they are going to let me use their id.
                • 5. Re: Is java:comp/env automatically prefixed ?
                  If not, please send me the test case directly...just add @oracle.com to my forum ID. However, note that if a patch is required, an SR will be required so that is the preferred route.