Posted Sun, 01 May 2005
Say you're working on a handful of different web application projects using one installation of Tomcat; it's very likely that you need different resources, settings, and runtime parameters per project - and as a consequence of such it's very likely that your tomcat configuration is a mess! Well no more, I say! What if you could have a distinct set of configurations for each project you're working on?
Fortunately Tomcat makes this extremely easy. There are two primary locations that Tomcat works with, identified by and . is the location you installed Tomcat into -- in my setup, that's /opt/tomcat. is where it will look for configuration files and other "dynamic portions" (according to tomcat's documentation) of the server.
What we're going to do is create one per project (or one for just the projects you think require their own, anyway), and then configure tomcat to use the new TOMCAT_BASE.
The first thing to do is create a local tomcat directory structure in your project directory -- my project looks
something like this:
MyProject/tomcat is going to be your .
MyProject/
docs/
etc/
src/
java/
test/
tomcat/
conf/
logs/
tmp/
webapps/
work/
You need to copy two files from /conf to /conf:
web.xml- Contains the default settings for all web apps deployed into .server.xml- Contains the server configuration. For my web projects, i usually useserver-minimal.xmlfile instead of the default server.xml, as it only loads the minimum amount of services needed to run a web application (which is usually sufficient for my hobby projects).
Once you have that done, your is ready for use. If you're launching Tomcat from the command line, you'll
want to set the environment variable CATALINA_BASE to point to your TOMCAT_BASE directory (MyProject/tomcat).
If you're launching Tomcat from
XCode, you'll want to open your custom executable's properties, and add the following argument:
Note: XCode appends arguments in order, so you'll want to put it somewhere before the argument that specifies the
Bootstrap class to launch.
-Dcatalina.base=../tomcat
All that's left to do is start deploying your project's webapp to /webapps rather than /webapps, and you're good to go. Your project's instance of Tomcat will log to MyProject/tomcat/logs, use MyProject/tomcat/work for its working directory, and MyProject/tomcat/tmp for tmp space.
Why would you want to do this, you ask? Well first and foremost, cuz it's cool. Second, perhaps you have projects that really should be tested and run in isolation. Third, maybe you don't have the luxury of having multiple machines that you can run webservers on, and you need to test a multi-server setup - or test communications between applications on separate app-servers. For me, it's a configuration-location thing - it lets you keep project-specific server configurations in your project, where they belong.
add to del.icio.us



