Tomcat
Tomcat ROOT.war deployment
If you wish to avoid having to deploy a web application explicitly named as ROOT.war – so that you use the default context URL “/” without having to resort to web server URL rewrites – it’s possible to do this and still maintain your application war files original name.
I thought it was worth writing about our approach to this as the Tomcat documentation isn’t particularly clear on how to achieve this.
As some background information, I work for a large FTSE100 company where a team other than the Development Team are responsible for the deployment of the application, and handing them a file called ROOT.war is a little unclear and could potentially lead to misunderstandings.
It’s possible to have the application context file point to a .war file outside of the Tomcat/webapps directory. Tomcat will then explode your war file, whatever it’s name, into the Tomcat/webapps/ROOT directory. Tomcat infers from the name of the context file that web application should be deployed as the default, accessible as root context “/”, without any need for web server URL rewrites.
<Context docBase="/<external_build_dir>/<application_name>.war" />
where <external_build_dir> can be any directory outside of Tomcat, for example your application build directory, and <application_name> can be the proper full name of your application.
If you are using Apache Ant deployment scripts, you can also make good use of a couple of features to automate this whilst maintaining naming clarity. We have a simple application context file <application_name>.xml:
<Context docBase="@DEPLOY_FILE@" />
and the associated application deployment script copies this file to the Tomcat conf directory, renaming it as ROOT.xml as so:
<copy file="${ant.project.name}.xml" tofile="${tomcat}/conf/Catalina/localhost/ROOT.xml">
<filterset>
<filter token="DEPLOY_FILE" value="${project.name}.war"/>
</filterset>
</copy>
As you can see it’s also using Ant’s filter task with a token to express the location of the application war file, pointing back at the build directory.
Of course, you can still use an Apache HTTP web server RewriteRule to serve your application from “/”, but this would apply to every request served:
RewriteRule /<application_name>/(.*) /$1
BOOTNOTE: Thanks to pid-2 for pointing out my initial mistake in this post.
There’s no need to set the path attribute of the context xml file, in fact Tomcat specifically states that you should not do this. The fact that you have a context file called ROOT.xml is enough for Tomcat to infer that you wish to deploy the web application as the root “/”.
Agile CTO
- tech_startup: Puppet certificate issues http://t.co/oM6y53rx 4 days ago
- have invented a new UNIX tool for cutting the grass: sudo chmown aeells:aeells squid.conf.bkp sudo: chmown: command not found 5 days ago
- I support #wikipediablackout Show your support here http://t.co/UFN8O0gk 2 weeks ago
- reasonable man adapts himself to world; unreasonable man tries to adapt world to himself; => all progress depends on unreasonable man. 3 weeks ago
- @blinkdesign we could do that too!!!!? ;o) in reply to blinkdesign 3 weeks ago
- @blinkdesign we could do something similar on our tech blog maybe... in reply to blinkdesign 3 weeks ago
- ".....in all things, the supreme excellence is simplicity." Henry Wadsworth Longfellow 3 weeks ago
- good day bootstrapping #tomcat #memcached to #aws server via #puppet - looking forward to provisioning entire production replica in minutes! 3 weeks ago
- great (practical) example of how to do #continousdeployment and branching within teams http://t.co/ceeyvD0h courtesy @chacon @domfarr 2012-01-05
- hi @ruv, mind if i ask how you came by that statistic? cheers! in reply to ruv 2012-01-02
- More updates...


