Tomcat and JNDI resources

I have a servlet being deployed to Tomcat 5.x.
How do I configure things so that when Im debugging my servlet, I can access the JNDI resources (specifically javax.sql.DataSources) that I have specified in my $TOMCAT_HOME/conf/server.xml ]]> ?

What should be in my web.xml in the webapp in order to link these things together?

8 comments
Comment actions Permalink

http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources-howto.html

Norris Shelton
Sun Certified Java Programmer




Nick Pratt wrote:

>I have a servlet being deployed to Tomcat 5.x.
>How do I configure things so that when Im debugging my servlet, I can access the JNDI resources (specifically javax.sql.DataSources) that I have specified in my $TOMCAT_HOME/conf/server.xml ? > >]]>What should be in my web.xml in the webapp in order to link these things together?

>

0
Comment actions Permalink

Ive read that a thousand times, and it makes no sense to me. Ive added the username/pwd to GlobalNamingResources.
Why isnt this enough?

I can deploy in JBoss dead easy. I just reference the damned JNDI names setup in the datasources XML, and everything just works, and works simply (remarkable for JBoss). Tomcat on its own - pain in the butt.

0
Comment actions Permalink

In article <41F50C08.9090804@yahoo.com>,
Norris Shelton <i.hate.spam@yahoo.com> wrote:

http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources-howto.html

Norris Shelton
Sun Certified Java Programmer




Nick Pratt wrote:

>I have a servlet being deployed to Tomcat 5.x.
>How do I configure things so that when Im debugging my servlet, I can access
>the JNDI resources (specifically javax.sql.DataSources) that I have
>specified in my $TOMCAT_HOME/conf/server.xml <GlobalNamingResources> ?
>
>What should be in my web.xml in the webapp in order to link these things
>together?

>


I think Nick is asking how to set this up in idea so the proper
resources get bound to servlet.xml, and that's something I've noticed
because and complained about. There is no way to deploy a webapp
specific descriptor with Tomcat on launch of run/debug, unless you use
an ant task, and that doesn't always work.

There should be something in our web app run/debu configuration which
lets us choose a context specific descriptor which gets deployed to the
Catalina/local directory on startup. That would solve it I think.

R

0
Comment actions Permalink

I think that's what Im asking.
I can get JNDI to work fine in JBoss - Id just like to develop my web apps / servlets using Tomcat since its a lot lighter, and starts up faster.

So, assuming my webapp is called "MyWebApp"
and this deploys to context path /MyWebApp
with a servlet "TestServlet" with a servlet mapping of /TestServlet/*

This servlet makes lookups on JNDI datasources.

Apart from adding the datasource info to the GLobalNamingParams, what else do I need to configure (either in IDEA or in Tomcat configuration files) to allow my servlet to access the JNDI resources.

Nick

0
Comment actions Permalink

In article <21729423.1106579577668.JavaMail.itn@is.intellij.net>,
Nick Pratt <no_mail@jetbrains.com> wrote:

I think that's what Im asking.
I can get JNDI to work fine in JBoss - Id just like to develop my web apps /
servlets using Tomcat since its a lot lighter, and starts up faster.

So, assuming my webapp is called "MyWebApp"
and this deploys to context path /MyWebApp
with a servlet "TestServlet" with a servlet mapping of /TestServlet/*

This servlet makes lookups on JNDI datasources.

Apart from adding the datasource info to the GLobalNamingParams, what else do
I need to configure (either in IDEA or in Tomcat configuration files) to
allow my servlet to access the JNDI resources.

Nick


Oh, you need to set that up under a context specific entry in
servlet.xml, then it will be available as long as you use the same
context name. That's why I don't like doing that, and would like to
think of a way for IDEA to do it for me in the run/debug config.

R

0
Comment actions Permalink

So simply putting the JNDI JDBC info into the GlobalNamingParameters section doesnt make it globally accessible by a simple:

Context ctx = new InitialContext();
ctx.lookup("jdbc/whateverDB" )

?

0
Comment actions Permalink

In article <20734393.1106584531657.JavaMail.itn@is.intellij.net>,
Nick Pratt <no_mail@jetbrains.com> wrote:

So simply putting the JNDI JDBC info into the GlobalNamingParameters section
doesnt make it globally accessible by a simple:

Context ctx = new InitialContext();
ctx.lookup("jdbc/whateverDB" )

?


Not in my experience. Tomcat is just dense that way, dunno if that's
who the reference impl should be...

There is a way to do it with a context specific xml as well, and that's
the way I prefer to do it, this way you don't modify a standard Tomcat
install. Create the file with your contextname.xml and have ant toss it
over before run debug into the Catalina/local dir of your Tomcat install.

R

0
Comment actions Permalink

Robert S. Sfeir wrote:

In article <20734393.1106584531657.JavaMail.itn@is.intellij.net>,
Nick Pratt <no_mail@jetbrains.com> wrote:

>>So simply putting the JNDI JDBC info into the GlobalNamingParameters section
>>doesnt make it globally accessible by a simple:
>>
>>Context ctx = new InitialContext();
>>ctx.lookup("jdbc/whateverDB" )
>>
>>?


Not in my experience. Tomcat is just dense that way, dunno if that's
who the reference impl should be...

There is a way to do it with a context specific xml as well, and that's
the way I prefer to do it, this way you don't modify a standard Tomcat
install. Create the file with your contextname.xml and have ant toss it
over before run debug into the Catalina/local dir of your Tomcat install.


I also have encountered a Tomcat bug where basically stuff in
GlobalNamingParameters does not work. Whereas the context-specific
XML file (which is well-supported by IDEA) does the trick.

Mind you, you've got to use the TC 5.5 syntax, not the TC 5.0 syntax, or
Tomcat silently fails to bind the resource. Damn it.

cheers,
David.

0

Please sign in to leave a comment.