Ben Ripkens

back to blog index

Define JNDI data source for Apache Tomcat

Defining data sources via JNDI has various benefits, e.g. pooling and completely external configuration. The latter is especially important as this avoids putting database credentials into your application. Since I'm currently studying the Spring framework, I also wanted to use another application server. In fact, I wanted to try Apache Tomcat 7, a servlet container.

I have to say that I found the JNDI how-to for Apache Tomcat insufficient and therefore want to share some information that I collected in addition to the how-to.

At first, they show what a context.xml file should look like but they don't tell you where to put it (ok they lead you to another documentation page). I found the simplest place to be the $CATALINA_BASE/conf/context.xml as this is probably sufficient for most use cases. Please note though that all deployed applications will have access to this data source. The next thing you shouldn't forget is to put the driver into $CATALINA_BASE/lib/. In combination with the aforementioned how-to this should be all you need to use JNDI data sources with Apache Tomcat.

That's me, Ben.
Hey, I am Ben Ripkens (bripkens) and this is my blog. I live in Düsseldorf (Germany) and I am employed by the codecentric AG as a Software Developer. When not working on enterprise applications as part of my job, I really like to dig into new paradigms for the development of web application front-ends and, recently, the Raspberry PI.