3 Replies Latest reply on Dec 8, 2004 10:46 PM by Joan Horta Tosas

    jndi's error

    Jin Di Newbie

      ejb-jar.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
      <ejb-jar>
       <enterprise-beans>
       <session>
       <ejb-name>mySessionEJB</ejb-name>
       <home>com.codemyth.study.mySessionHome</home>
       <remote>com.codemyth.study.mySession</remote>
       <ejb-class>com.codemyth.study.mySessionBean</ejb-class>
       <session-type>Stateless</session-type>
       <transaction-type>Container</transaction-type>
       </session>
       </enterprise-beans>
      </ejb-jar>

      jboss.xml
      <?xml version="1.0"?>
      <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN"
       "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
      <jboss>
       <enterprise-beans>
       <session>
       <ejb-name>mySessionEJB</ejb-name>
       <jndi-name>ejb/mySessionEJB</jndi-name>
       </session>
       </enterprise-beans>
      </jboss>
      


      there is nothing in web.xml and jboss-web.xml


      but when i
      InitialContext.lookup("java:comp/env/ejb/mySessionEJB")--------error;
      InitialContext.lookup("ejb/mySessionEJB")--------error;
      InitialContext.lookup("mySessionEJB")--------error;

      how do the program will correctly?


        • 1. Re: jndi's error
          Darran Lofthouse Master

          Use JNDI View in jmx-console to see what is actually bound.

          • 2. Re: jndi's error
            chuck hutchinson Newbie

            Hi

            I am new to jboss and and looking through the posts to find my problem with JNDI which looks very similar to the one that codemyth has. Mine though is with a simple data source using jboss 3.2.6. Codemyth's problem was related to jndi-ejb lookups.

            Here is my source:

            part of web.x.xml where my datasource is defined:

            <resource-ref>
            blah
            <res-ref-name>jdbc/honeypot</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
            </resource-ref>

            part of jboss-web.xml where a different resource-ref is defined for jboss (I don't know WHY I need this but I found it on a different forum saying that I would need to define it here - so I did and here it is!):

            <resource-ref>
            <res-ref-name>jdbc/honeypot</res-ref-name>
            <jndi-name>jdbc/honeypot</jndi-name>
            </resource-ref>


            Next is my snippet of code that looks up the resource:

            log.info ("Creating initial context");
            props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
            props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
            props.put(Context.PROVIDER_URL, "jnp://localhost:1099");

            initCtx = new InitialContext(props);

            listContext (initCtx);
            log.info ("Getting honeypot datasource!");

            dataSource = (DataSource)initCtx.lookup ("java:comp/env/jdbc/honeypot");

            log.info ("Getting Connection!");

            Now part of the exception trace that I am getting:
            2004-12-08 16:04:38,221 INFO [STDOUT] javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: jdbc not bound]
            2004-12-08 16:04:38,231 INFO [STDOUT] at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:972)
            2004-12-08 16:04:38,231 INFO [STDOUT] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:615)
            ...
            ...
            ...

            Now I can print out the JNDI tree under "java:comp/env/jdbc" and I do see the "honeypot" entry. But when I look it up this is where I get the exception.

            • 3. Re: jndi's error
              Joan Horta  Tosas Novice

              Where are you trying to access the EJBs? In the web tier? If so, you must define the reference in web.xml and jboss-web.xml files.