Tips on Tomcat - moving applications around
Archive - Originally posted on "The Horse's Mouth" - 2013-02-05 15:55:56 - Graham EllisIf you want to replace the root application on your Tomcat server, you can replace the ROOT folder in webapps. But there's alternatives that might be better for you.
a) Place the .war file and / or application in webapps, and replace the ROOT folder with a symbolic link to the application:
cd /usr/local/tomcat/webapps
mv ROOT BRANCH
cp {wherever/whatever} myrootapp.war
mkdir myrootapp
cd myrootapp
jar xf ../myrootapp.war
With the last three lines only being needed if you've turned autodeploy off (a stonking good idea on a production machine!). Note that I've moved the original ROOT application - that's just in case I want to get back to it later ... then
cd ..
ln -s myrootapp ROOT
b) A varient on (a). On a production server, you won't want your web applications to live within /usr/local/tomcat (or equivalent); that's for tomcat itself and the configurations - vital software, but rarely changing. You'll want your webapps instead in a directory / disc area that's backed up much more often (because it's going to change more) and is available to the people who look after the application rather than the people who look after the running of the server.
mkdir /var/www/webapps
cp {wherever/whatever} /var/www/webapps/myrootapp.war
cd /var/www/webapps
mkdir myrootapp
cd myrootapp
jar xf ../myrootapp.war
cd /usr/local/tomcat/webapps
mv ROOT BRANCH
ln -s /var/www/webapps/myrootapp ROOT
c) If you wish to move all of your applications served by Tomcat to a separate area, you can change the appBase attribute of the Host element in your server.xml configuration file. Carrying on using the data we have above:
<Host name="localhost" appBase="/var/www/webapps" ...
becomes
<Host name="localhost" appBase="webapps" ...
and indeed you can set up symbolic links within that directory to reroot root application requests from ROOT to some other application.
Note that option (b) - with a symbolic link from one directory to another - means that the web application will only be visible via ROOT and not via its own name, whereas with options (a) and (c) it is visible both ways.
The above are just examples of what you might do; you'll also want to consider the effect of the choice you make on the autodeployer and on the Tomcat Manager application if you're running it.
Want to know more? We run Apache http and Apache Tomcat training course - see [here].