tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Tomcat & JNDI
Date Tue, 07 Nov 2000 02:21:04 GMT
"Roytman, Alex" wrote:

> I am trying to tie Tomcat with JNDI to use J2EE pattern to obtain resources:
> Context context = new InitialContext();
> dataSource = (DataSource)context.lookup("java:comp/env/jdbc/myDataSource");
> (I know Tomcat team is planning to have it for Tomcat 4 eventually)

Interesting timing ... the code to do this (in Tomcat 4) was added just in the
last couple of days (after milestone 4).

> I have my own little in memory JNDI implementation with support for
> java:comp URLs
> and it works fine but provides one global JNDI for all contexts defined in
> server.xml while it should be context specific. Basically the problem is how
> to make InitialContext() tomcat context aware (to be precise to make my
> java:comp namespace to start from different roots depending on where
> InitialContext was created).
> If AdaptiveClassLoader had some context info in it I could get it from there
> while creating InitialContext.

If I recall correctly, it's actually sort of tricky to get this right.  You
might want to check the source for the Tomcat 4 implementation for ideas -- I
believe it depends on the servlet container calling
Thread.setContextClassLoader() once you know which webapp you're running in.
This only works in a Java2 environment, though.

> Any ideas are greatly appreciated
> Alex

Craig McClanahan

View raw message