Tomcat documentation says:
The locations for Context Descriptors are;
$CATALINA_HOME/conf/[enginename]/[hostname]/context.xml
$CATALINA_HOME/webapps/[webappname]/META-INF/context.xml
On my server, I have at least 3 files floating around:
1 ...tomcat/conf/context.xml
2 ...tomcat/Catalina/localhost/myapp.xml
3 ...tomcat/webapps/myapp/META-INF/context.xml
What is the order of precedence?
Best Answer
For the files you listed, the simple answer assuming you are using all the defaults, the order is (note the conf/Catalina/localhost):
I'm basing this (and the following discussion) on the Tomcat 5.5 official documentation for the Context Container.
So if that's the simple answer, whats the complete answer?
Tomcat 5.5. will look in a couple of other places for
<Context>
elements beyond those you've listed (see the official docs).The
META-INF/context.xml
will never be opened if Tomcat finds aCatalina/localhost/myapp.xml
. So if you actually have all the files above, its more correct to say the theMETA-INF/context.xml
is irrelevant, not that it's the lowest precedence.If you say
<Context override="true" ...>
in yourCatalina/localhost/myapp.xml
that will make it the highest precedence, regardless ofconf/context.xml
. Same thing in yourMETA-INF\context.xml
, as long as you don't have aCatalina/localhost/myapp.xml
(see previous paragraph).Also, the
/Catalina/localhost/
portion of the path in the files above actually comes out of the "default"conf/server.xml
and matches the<Engine name="Catalina" defaultHost="localhost">
. If yourserver.xml
uses different values forname
anddefaultHost
in the<Engine>
, that's the dir structure where Tomcat will look.Finally, for the
...tomcat\
portion of the files you listed, Tomcat uses the dir from the$CATALINA_BASE
environment variable. If that's not set, then it uses the dir from the$CATALINA_HOME
environment variable, which is the directory of the Tomcat installation. I like to set and use$CATALINA_BASE
so that I don't "pollute" my Tomcat installation.