Using JNDI Resources in Tomcat

  • Follow


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
0
Reply thomas-spam (1) 8/20/2004 8:26:55 AM

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)
0
Reply Juha.Laiho (584) 8/20/2004 5:12:03 PM


1 Replies
26 Views

(page loaded in 0.139 seconds)


Reply: