Using JNDI Resources in Tomcat - Java

This is a discussion on Using JNDI Resources in Tomcat - Java ; Hello! I have several webapps installed on my tomcat that share various configuration elements (config-params, resource-info etc.) Currently I have them configured as init-params in their deployment-descriptors (web.xml). Waht I want to do is to configure them on a single ...

+ Reply to Thread
Results 1 to 2 of 2

Using JNDI Resources in Tomcat

  1. Default Using JNDI Resources in Tomcat

    Hello!

    I have several webapps installed on my tomcat that share various
    configuration elements (config-params, resource-info etc.)
    Currently I have them configured as init-params in their
    deployment-descriptors (web.xml).

    Waht I want to do is to configure them on a single point and have the
    possibility to change it during runtime.
    So I thought about doing this:
    Setting up some JNDI-Environment entries in my tomcat-server and link to
    them from my webapp.

    I can see my environment etries in the admin webapp.
    I have something like this in my web.xml:

    <resource-env-ref>
    <resource-env-ref-name>someInfo</resource-env-ref-name>
    <resource-env-ref-type>java.lang.String</resource-env-ref-type>
    </resource-env-ref>

    and the JNDI entry in my server.xml looks like this:

    <Environment description="" name="someInfo" override="false"
    type="java.lang.String" value="hello world"/>

    My code to lookup the entry is this:

    String someInfo = (String) ctx.lookupLink("java:/comp/env/someInfo");

    But I keep getting a NamingException.
    If I iterate over my ctx.list("java:/comp/env");

    I see there is a variable "someInfo" and isRelative() is true.

    How can I access those global env. entries? Am I doing something wrong?
    Is there a good tutorial on this one? (I've read tomcat jndi stuff and
    searched the web for tutorials already)
    Can you tell me the "best practice" how to acomplish such task (maybe
    having default params and webapp-dependent entries and
    webapp-independent entries).

    Thank you very much!

    Thomas Bauer

  2. Default Re: Using JNDI Resources in Tomcat

    Thomas Bauer <thomas-spam@bauer.dhs.org> said:
    >I have several webapps installed on my tomcat that share various
    >configuration elements (config-params, resource-info etc.)
    >Currently I have them configured as init-params in their
    >deployment-descriptors (web.xml).
    >
    >Waht I want to do is to configure them on a single point and have the
    >possibility to change it during runtime.
    >So I thought about doing this:
    >Setting up some JNDI-Environment entries in my tomcat-server and link to
    >them from my webapp.

    ....
    >How can I access those global env. entries? Am I doing something wrong?
    >Is there a good tutorial on this one? (I've read tomcat jndi stuff and
    >searched the web for tutorials already)


    Have you looked at the JndiServlet among the examples distributed with
    Tomcat?
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)

+ Reply to Thread

Similar Threads

  1. Jndi, Tomcat, Mysql settup and Servlet test
    By Application Development in forum Java
    Replies: 0
    Last Post: 11-18-2007, 03:15 AM
  2. Replies: 1
    Last Post: 06-25-2007, 02:28 PM
  3. tomcat plugin for eclipse - tomcat not starting
    By Application Development in forum Java
    Replies: 0
    Last Post: 03-27-2006, 05:01 PM
  4. Re: Tomcat and JNDI resources
    By Application Development in forum J2EE
    Replies: 0
    Last Post: 01-05-2006, 10:30 AM
  5. configuring tomcat 5.5.8, JNDI datasource with Oracle 10g
    By Application Development in forum JDBC JAVA
    Replies: 0
    Last Post: 04-07-2005, 10:06 AM