- In the $CATALINA_BASE/conf/context.xml file: the Context element information will be loaded by all webapps.
- In the $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all webapps of that host.
- In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The name of the file (less the .xml extension) will be used as the context path. Multi-level context paths may be defined using #, e.g. foo#bar.xml for a context path of /foo/bar. The default web application may be defined by using a file called ROOT.xml.
- Only if a context file does not exist for the application in the $CATALINA_BASE/conf/[enginename]/[hostname]/, in an individual file at /META-INF/context.xml inside the application files. If the web application is packaged as a WAR then /META-INF/context.xml will be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to match the application's context path. Once this file exists, it will not be replaced if a new WAR with a newer /META-INF/context.xml is placed in the host's appBase.
- Inside a Host element in the main conf/server.xml.
Perhaps the context of my application is already defined in some of server configuration files and will not be rewrote even I specify it in META-INF/context.xml ?
Pongsakorn you can just keep xxx.xml in /conf and give path to target. And there is no other file where configuration is kept for your deployment, in that case just dont put your war inside your webapps directory. Everything should work fine.
Couple of things to be aware of when using the externally-applied context.xml file:
1. An external context.xml will override (completely) the META-INF/context.xml file (if there is one).
2. The actual name of an external context.xml file (unlike the one in META-INF) is almost never literally "context.xml". It cannot be, since that would only allow deploying one context (webapp), and directories can only hold 1 copy of a given filename.
3. The actual context name that a webapp will appear under when using an external context.xml will be the name of the context.xml file, and NOT what you defined in the Context element within that file. The context name in the context.xml file is only used when it is an internal (META-INF/context.xml). I'm not very happy about that, but that's how it works. So if you define a $CATALINA_BASE/conf/catalina/localhost/fubar.xml file, the webapp will appear at http://localhost:8080/fubar.