Dynamic Tomcat configuration using parameter substitutions

  • strict warning: Non-static method view::load() should not be called statically in /hermes/walnaweb12a/b57/moo.greydragoncom/nodsw/sites/all/modules/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /hermes/walnaweb12a/b57/moo.greydragoncom/nodsw/sites/all/modules/views/handlers/views_handler_argument.inc on line 744.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /hermes/walnaweb12a/b57/moo.greydragoncom/nodsw/sites/all/modules/views/handlers/views_handler_filter.inc on line 607.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /hermes/walnaweb12a/b57/moo.greydragoncom/nodsw/sites/all/modules/views/handlers/views_handler_filter.inc on line 607.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /hermes/walnaweb12a/b57/moo.greydragoncom/nodsw/sites/all/modules/views/handlers/views_handler_filter_boolean_operator.inc on line 159.
Leeland's picture

I was looking for a way to make a dynamic Tomcat configuration that could leave off editing XML files. I knew that Tomcat supported parameter substitution. However, I could not find a list of what was provided by default. Yes I know the phrase "your mileage my vary" applies deeply to this. None the less it seemed to me there had to be a reasonable list.

I knew it was there from the Tomcat 5.5 SSL setup instructions (http://tomcat.apache.org/tomcat-5.5-doc/ssl-howto.html) which used ${user.home} in the examples. The Configuration for 3.3 guide (http://tomcat.apache.org/tomcat-3.3-doc/serverxml.html) gave some additional clues. Finally digging through Googling brought up the 2008 conversation thread (${user.home} and other server.xml tags accepted by Tomcat?).

Basically if you are using Tomcat 5.5 or better Tomcat supports parameter substitution in its configuration files using the ANT style ${var}. The variables available are pulled in via System.getProperties() automatically. Further you can push variables into this area from the command line using the -Dname=value option for the Tomcat launch.

There are a couple of properties automatically added by Tomcat as part of its startup such as catalina.home and catalina.base (again both of these are on the command line just do a 'ps auxwww | grep java' to see them.

Additionally you can inject others via the properties file ${catalina.base}/conf/catalina.properties. Or via the ${catalina.base}/conf/context.xml.

Which properties are available at what time is a little vague. For example all of them are available by the time server.xml is read. However, only -D command line parameters such as catalina.base and catalina.home are present when the file catalina.properties itself is loaded. The log4j.properties allows general system properties. I have not yet tested to see what if any are available for context.xml and web.xml. Further I would discourage using any particular order unless it was clearly documented as it could change at any update to Tomcat.

To discover what was there by default I created a blank Tomcat 6 instance, fed it a JSP page with the following code:

<html>
<head>
<title>Tomcat Properties</title>
</head>
<body>
<pre>
<%
// Get all system properties
java.util.Properties props = System.getProperties();
// Enumerate all system properties
java.util.Enumeration e = props.propertyNames();
for (; e.hasMoreElements(); ) {
// Get property name
String propName = (String)e.nextElement();

// Get property value
String propValue = (String)props.get(propName);
out.println(propName + " = " + propValue);
}
%>
</pre>
</body>
</html>

From which I examined the results and reduced them to this list:

catalina.base = /var/lib/tomcat6
catalina.home = /usr/share/tomcat6
file.separator = /
java.endorsed.dirs = /usr/share/tomcat6/endorsed
java.home = /usr/lib/jvm/java-6-openjdk/jre
java.io.tmpdir = /tmp/tomcat6-tmp
java.util.logging.config.file = /var/lib/tomcat6/conf/logging.properties
java.util.logging.manager = org.apache.juli.ClassLoaderLogManager
user.dir = /var/lib/tomcat6
user.home = /usr/share/tomcat6
user.name = tomcat6

From here I am going to mess with the input command line to get a few extra items into the mix.

Hope this helped!

Thread Slivers eBook at Amazon