Which Tomcat 5 context file takes precedence?
Asked Answered
J

3

20

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?

Juanjuana answered 26/11, 2008 at 21:40 Comment(0)
E
36

For the files you listed, the simple answer assuming you are using all the defaults, the order is (note the conf/Catalina/localhost):

...tomcat/conf/context.xml
...tomcat/conf/Catalina/localhost/myapp.xml
...tomcat/webapps/myapp/META-INF/context.xml

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 a Catalina/localhost/myapp.xml. So if you actually have all the files above, its more correct to say the the META-INF/context.xml is irrelevant, not that it's the lowest precedence.

If you say <Context override="true" ...> in your Catalina/localhost/myapp.xml that will make it the highest precedence, regardless of conf/context.xml. Same thing in your META-INF\context.xml, as long as you don't have a Catalina/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 your server.xml uses different values for name and defaultHost 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.

Erythromycin answered 26/11, 2008 at 23:32 Comment(1)
Wow, a very detailed and impressive answer. Thank you.Incinerator
S
1

My understanding is:

  • tomcat/conf/context.xml is the "default" context.xml whose contents are overlayed with the webapp context definitions. My TC 5 default context.xml has almost nothing in it, other than listing the web.xml as a watched resource, which supports this notion.
  • tomcat/Catalina//.xml is used for the webapp. Either it is place here manually, or is taken from your webapp at deployment time...so this is the real master that TC uses. If you edit this changes will be read next start.
  • tomcat/webapps/myapp/META-INF/context.xml - this is copied to tomcat/Catalina/ upon initial deployment if you alter this after initial deployment, I don't think that has any effect
Seignior answered 26/11, 2008 at 22:11 Comment(0)
S
0

I haven't found any official documentation, but I have observed the load order to be:

1 tomcat_home/conf/context.xml
2 tomcat_home/webapps/myapp/META-INF/context.xml

Where #2 is the last one applied (so its settings override all previous ones, where applicable).

I have never used the webapp named context files (your option #2).

Scorper answered 26/11, 2008 at 22:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.