I'm currently editing the server.xml context paths and want to have a context path back to the original webapps directory. Is there an built in tomcat environment variable that points back to the tomcat installation directory like TOMCAT_HOME or something?
1 回答
As pointed out in the comments, the Tomcat installation directory is available as ${catalina.home}
property, while the Tomcat instance root directory through ${catalina.base}
(cf. Tomcat documentation). E.g. you can use ${catalina.home}/webapps/manager
for the location of the Tomcat Manager application.
However I wouldn't define the contexts for Tomcat Manager and other applications in server.xml
: they have their own context definitions in the META-INF/context.xml
file of their folder, so they probably should not be redefined in server.xml
: this way you can loose some important configuration attributes (like privileged="true"
for Tomcat Manager).
A better solution would be to copy those definitions into conf/Catalina/localhost/<appname>.xml
and add the docBase="${catalina.home}/webapps/<appname>
attribute. E.g. for Tomcat Manager you should create a file named conf/Catalina/localhost/manager.xml
with content:
<Context docBase="${catalina.home}/webapps/manager" antiResourceLocking="false" privileged="true" >
<CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
sameSiteCookies="strict" />
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
<Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>