Apache
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 “/”.
Blogroll
Tech Startup
- "I don't want to be a product of my environment. I want my environment to be a product of me." - Frank Costigan, The Departed 1 week ago
- Actually said 'Good Morning' to his Mac when it it announced 'It's 8 o'clock'. Taking it to a whole new level... 1 week ago
- @auxbuss have found mockflow more helpful lately, partly as it's integrated with google apps. balsamiq has a more aesthetic UI though ;o) 1 week ago
- is reading up on #NoSQL and how best to store several '000 small read-only data tables. answers on a postcard please ;o) 1 week ago
- is now a big big fan of #git still getting there with the command line though, latest learning is git log --name-status 3 weeks ago
- @lleighton something i can help with? in reply to lleighton 3 weeks ago
- has broken the @Oracle database. that's a first ;o) 2010-07-17
- how to extend base or framework test classes from another module with #maven http://bit.ly/5hSvg 2010-06-24
- #java #developers. Interested in an #agile financial services #startup with secured funding? http://bit.ly/a0NNiX 2010-06-16
- looking into #oracle 11g UCP 2010-05-27
- More updates...
