Using JNDI Resources in Tomcat

T

Thomas Bauer

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
 
J

Juha Laiho

Thomas Bauer 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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top