Java Notes From My Desktop

Tags - Categories : All | Articles | Book Reviews | CSS | Java | Javaranch | Javascript | News | Opengl | Opinions | Personal | php

Several weeks ago I added Tomcat's Ant tasks to one of my projects to make test deployment easier on me. Everything was working great until I started adding the Data Access layer into my web application and needed to configure my JNDI resource. I don't like putting application specific contexts in my server.xml file. I prefer to create a seperate XML file and place it in the TOMCAT_HOME/conf/Catalina/localhost folder.

I added the following task to my build.xml file.

When I ran the deploy task, everything seemed to work just fine. The war was copied and deployed. However, the context config file (anykey.xml) was not copied. So I re-read the ant task API. It said:
Config - URL of the context configuration file for this application, if any.

So I am thinking, this has to be the way to do it. After reading through countless pages of documentation on the web both on Tomcat's web site and googling for information from other users having a similar problem, and with no luck, I finally decided to break down and join the Tomcat user's mailing list. And I got the solution within minutes of posting my problem. Kudos to those mailing list folks, specifically Pillip Qin. And here is the answer.

Your context config file needs to be named context.xml. Then, use the metainf attribute of the WAR task so that context.xml gets placed in the META-INF folder of your application. Remove the config attribute from the deploy task. The context.xml gets renamed to whatever your webapp context name is when you deploy the web app and is copied to the appropriate folder and all is well with the world.