Referencing Environment Variables in web.xml

You can use Ant-style variable substitution in any of the tomcat xml config files, such as:


Where foo is a Java System Property (sysprop).

You can’t use OS Environment Variables (envvars) directly, I think…

To use envvars, you can put


in bin/setenv.bat (or similarly in bin/ for *nix). You may need to create that file. Tomcat will run this file when it starts.

As CATALINA_OPTS is an envvar (as opposed to a command line option), it should not be visible by other users on the system (save ancient Unixes), though I haven’t tested this.

If you are using Spring, you can create a <context:property-placeholder/> bean and then directly use envvars or sysprops in Spring XML config files (though not web.xml).

Leave a Comment