Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using environment variables in Tomcat/Catalina Context docBase configuration

I'm not a big tomcat user, but our project is using it currently. We've committed a .xml configuration file that is placed in CATALINA_HOME\localhost, but get's updated rather often. I would much prefer to symlink this file into that CATALINA_HOME\localhost directory from our working directory. Unfortunately, the docBase path has to be modified per developer.

Is there a way to use environment variables in the docBase path so that developers can keep their projects where they please and our startup scripts can symlink the catalina xml configuration?

I would like something like this:

....

like image 404
Ryan Cromwell Avatar asked Feb 06 '12 14:02

Ryan Cromwell


1 Answers

Here's what I did in Tomcat7 (I think you'll have no problem doing it in other versions of Tomcat):

in setenv.bat I added the following line:

set JAVA_OPTS=%JAVA_OPTS% -DAPP_PATH="c:\path\to\app"

in my webapp.xml (located in C:\path-to-apache-tomcat\conf\Catalina\localhost)

I did the following:

<Context docBase="${APP_PATH}\src\main\webapp">

Hope this helps!

like image 76
Joao Baltazar Avatar answered Sep 20 '22 13:09

Joao Baltazar