tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Brock <>
Subject Programatically setting web.xml in embedded Tomcat
Date Fri, 24 Jun 2011 12:53:08 GMT
Hi all,

I'm currently using Tomcat's embedded feature for unit testing of a web
service. This web service displays different behaviour depending on the
contents of the web.xml file. I therefore want to exercise different web.xml
configurations in my unit tests. Currently the setup code I'm using is as

Tomcat tomcat = new Tomcat();
tomcat.addWebapp("/ServiceTest", System.getProperty("user.dir") +

As you can see, the webapp is currently sourced from the NetBeans build

What is the best way for me to test different web.xml files? Is there a way
I can set the webapp to the same directory as I am currently, but point at a
web.xml file that is somewhere else?

(I'm not too keen on altering the build/web directory just in case the test
fails and ends up breaking the real web.xml file.)

My fall-back position is to have my test cases make a temporary copy of the
build/web directory and then override the web.xml file with the one I want
to use in that specific test case, but I was wondering if there is a more
elegant solution.

My environment is:

Tomcat 7.0.11
NetBeans 7.0
Windows XP



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message