No object bound for java:comp/env ???

Discussions

EJB programming & troubleshooting: No object bound for java:comp/env ???

  1. No object bound for java:comp/env ??? (9 messages)

    Hi all,

    I have no problem calling my EJB from client App, but when I try to read value in environment entries it fails with the following message :

    javax.naming.NameNotFoundException: No object bound for java:comp/env
    at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:116)
    at javax.naming.InitialContext.lookup(InitialContext.java:347)
    at SSBean.SecurityBeanTestClient.<init>(SecurityBeanTestClient.java:34)
    at SSBean.SecurityBeanTestClient.main(SecurityBeanTestClient.java:158)

    My code is :

    Context Init = new InitialContext();
    Context Env = (Context)Init.lookup("java:com/env");

    I've set a value in environment entries tab in Deploytool.

    What's wrong ? Please help.


    Setya

    Threaded Messages (9)

  2. No object bound for java:comp/env ???[ Go to top ]

    Try
    "java:comp/env"
    instead of
    "java:com/env"
  3. No object bound for java:comp/env ???[ Go to top ]

    Sorry, I did type "comp" in my program, it's only a typho in this forum because the error message says "java:comp/env".

    I also have EJB on the server with JNDI name ejb/SecurityBean when I call it just "ejb/SecurityBean" it works fine, but when I call it with full path specification "java:comp/env/ejb/SecurityBean" it produces the same error as above.

    Please help.

    Setya
  4. No object bound for java:comp/env ???[ Go to top ]

    Add <ejb-ref>...</ejb-ref> in your web.xml file if you call the EJB from an Servlet.
  5. No object bound for java:comp/env ???[ Go to top ]

    Is it your Session Bean that is trying to lookup java:comp/env? or the TestClient? The error looks like the test client program is trying to do the lookup. Only the bean itself will be able to see the magical java:comp/env.
  6. No object bound for java:comp/env ???[ Go to top ]

    Yeah, I think this changed with the change from the 1.1 to 1.2 spec. In older client programs looking up EJBs the default was always that they were under comp/env, but now they just are at wherever you put them. So, for instance, if you are using weblogic and you put this in your weblogic-ejb-jar.xml file for the bean:

    <jndi-name>TestBean</jndi-name>

    You get it back like:

    Object ref = jndiContext.lookup("TestBean");
  7. No object bound for java:comp/env ???[ Go to top ]

    Thanks,

    Yes, I try to lookup from TestClient, so I guess this is the mistake ?

    Setya
  8. No object bound for java:comp/env ???[ Go to top ]

    Yeah. The "java:comp/env" context is a magical one.
    Imagine if two EJBs have a value they want to store called "host". They can set that up in the <env-entry>'s

    Bean A: host=hostA.com
    Bean B: host=hostB.com

    although the JNDI name for each bean to get this entry is the same: java:comp/env/host
    Each one will get the right value (its own).

    This is all due to the fact that java:comp/env is special for J2EE components. A normal client will not be able to find a reference, environment entry, or what have you via that context. That is why the test client isn't finding anything... it would need the *real* jndi name, not the reference
  9. No object bound for java:comp/env ???[ Go to top ]

    Thanks a lot Mr. Dion for your explanation,

    I understand now, but since now I can retrieve the value, how can I change the present value or add new ones programmatically ?


    Setya
  10. No object bound for java:comp/env ???[ Go to top ]

    I am sorry...this might be a little late.
    But could you tell me how you resolved this problem?

    Thanks much,
    bens