5 Replies Latest reply on Jul 24, 2003 10:44 AM by shaun

    Cannot find environment parameter

      I setup an environment property in my ejb-jar.xml file as-

      <enterprise-beans>

      ...
      <!--This element is an environment variable only available in jlidState-->
      <env-entry>
      This element is an environment variable representing the start ID of the JLID entry. For example if the startJLID is 50000 then only JLIDS above 50000 should be displayed.

      <!--The JNDI location for the environment variable is java:comp/env/startJLID-->
      <env-entry-name>startJLID</env-entry-name>
      <env-entry-type>java.lang.String</env-entry-type>
      <env-entry-value>50000</env-entry-value>
      </env-entry>

      </enterprise-beans>

      and try and access it in my code by

      /*
      * get the startJLID environment variable from ejb-jar.xml
      * /
      Context initCtx = new InitialContext();
      String startJLID = (String) initCtx.lookup("java:/comp/env/startJLID");
      System.out.println("startJLID : "+startJLID);

      but I get a javax.naming.NameNotFoundException : startJLID not bound

      I'm using JBoss 3.0.3 + tomcat (this is virtually copied straight out of the Mastering EJB book by Roman et al)

      Any ideas what's wrong?

      Thanks in advance,
      Shaun

        • 1. Re: Cannot find environment parameter

          Post the full thing,
          your post shows
          then

          • 2. Re: Cannot find environment parameter

            Here's the whole thing

            <?xml version="1.0"?>
            <!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>

            <ejb-name>Lesson</ejb-name>
            jlids.lesson.LessonHome
            jlids.lesson.Lesson
            <local-home>jlids.lesson.LessonLocalHome</local-home>
            jlids.lesson.LessonLocal
            <ejb-class>jlids.lesson.LessonBean</ejb-class>
            <persistence-type>Bean</persistence-type>
            <prim-key-class>jlids.lesson.LessonPK</prim-key-class>
            False
            <resource-ref>
            <res-ref-name>jdbc/MySqlDS</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
            </resource-ref>



            <ejb-name>jlidState</ejb-name>
            jlids.jlidSession.jlidStateHome
            jlids.jlidSession.jlidState
            <ejb-class>jlids.jlidSession.jlidStateBean</ejb-class>
            <session-type>Stateful</session-type>
            <transaction-type>Container</transaction-type>
            <!--This element is an environment variable only available in jlidState-->
            <env-entry>
            This element is an environment variable representing the start ID of the JLID entry. For example if the startJLID is 50000 then only JLIDS above 50000 should be displayed.

            <!--The JNDI location for the environment variable is java:comp/env/startJLID-->
            <env-entry-name>startJLID</env-entry-name>
            <env-entry-type>java.lang.String</env-entry-type>
            <env-entry-value>50000</env-entry-value>
            </env-entry>

            </enterprise-beans>


            <assembly-descriptor>
            <container-transaction>

            <ejb-name>Lesson</ejb-name>
            <method-intf>Local</method-intf>
            <method-name>*</method-name>


            <ejb-name>Lesson</ejb-name>
            <method-intf>Remote</method-intf>
            <method-name>*</method-name>

            <trans-attribute>Required</trans-attribute>
            </container-transaction>
            </assembly-descriptor>
            </ejb-jar>


            Shaun

            • 3. Re: Cannot find environment parameter
              radl01

              Hi,

              try to look at JNDIView (jmx-console) where the env var. is registered.

              Jan

              • 4. Re: Cannot find environment parameter

                It confirms it's not there.

                • 5. Re: Cannot find environment parameter

                  The error was in the code!

                  String startJLID = (String) initCtx.lookup("java:/comp/env/startJLID");

                  String startJLID = (String) initCtx.lookup("java:comp/env/startJLID");

                  Schoolboy error on my part!