Using environment variables in Tomcat/Catalina Context docBase configuration
Asked Answered
S

1

10

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:

....

Swane answered 6/2, 2012 at 14:34 Comment(0)
F
21

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!

Fraction answered 23/5, 2012 at 10:44 Comment(1)
After 7 years, it's about time this received full answer level 😄. Thanks Joao!Swane

© 2022 - 2024 — McMap. All rights reserved.