Wednesday, December 06, 2006

Where is my context.xml coming from!?!

I recently modified some JSPs that were being served by Tomcat. Specifically, I added some 'Environment Entries' so that I could set some 'global' variables for my webapp.


I added things like the following to my context.xml file in the META-INF directory of my webapp:
<Environment name="maxExemptions" value="10" type="java.lang.Integer"/>

So that during execution I could do load the variable and use it like so:



Context c = new InitialContext();
String maxExemptions =
((Integer)c.lookup("java:comp/env/maxExemptions")).intValue();


After I deployed my new code, I tested it and found out quickly that the javax.naming.NamingException were being throw. The error basically stated that the variable was not bound in this context.

At first I thought that I did the whole looking up stored properties incorrectly. What really happened though, was that in my

/${catalina.home}/conf/Catalina/localhost/

directory was a cached copy of my context.xml file under the name of 'my_webapps_name'.xml.

Once I deleted that and restarted Tomcat, everything worked as expected.

If you came here trying to debug javax.naming.NamingExceptions, I recommend that you first try removing that file first!

Good Luck!

1 comment:

Anonymous said...

Thank you so much for the tip! Saved my day ;-)