java 哪个 Tomcat 5 上下文文件优先?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/322260/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Which Tomcat 5 context file takes precedence?
提问by jeph perro
Tomcat documentationsays:
The locations for Context Descriptors are;
上下文描述符的位置是;
$CATALINA_HOME/conf/[enginename]/[hostname]/context.xml
$CATALINA_HOME/webapps/[webappname]/META-INF/context.xml
$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:
在我的服务器上,我至少有 3 个文件浮动:
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?
优先顺序是什么?
回答by netjeff
For the files you listed, the simple answer assuming you are using all the defaults, the order is (note the conf/Catalina/localhost):
对于您列出的文件,假设您使用所有默认值的简单答案,顺序是(注意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.
我将此(以及以下讨论)基于Context Container的Tomcat 5.5 官方文档。
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).
雄猫 5.5。将在其他几个地方查找<Context>您列出的元素之外的元素(请参阅官方文档)。
The META-INF/context.xmlwill 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.xmlis irrelevant, not that it's the lowest precedence.
该META-INF/context.xml如果Tomcat发现一个永远不会被打开Catalina/localhost/myapp.xml。因此,如果您确实拥有上述所有文件,则更正确地说 the META-INF/context.xmlis inrelevant,而不是最低优先级。
If you say <Context override="true" ...>in your Catalina/localhost/myapp.xmlthat will make it the highestprecedence, 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).
如果你说<Context override="true" ...>在你的Catalina/localhost/myapp.xml那将使它成为最高优先级,不管conf/context.xml. META-INF\context.xml只要您没有Catalina/localhost/myapp.xml(见上一段),在您的中也一样。
Also, the /Catalina/localhost/portion of the path in the files above actually comes out of the "default" conf/server.xmland matches the <Engine name="Catalina" defaultHost="localhost">. If your server.xmluses different values for nameand defaultHostin the <Engine>, that's the dir structure where Tomcat will look.
此外,上述/Catalina/localhost/文件中的路径部分实际上来自“默认”conf/server.xml并与<Engine name="Catalina" defaultHost="localhost">. 如果您server.xml在name和defaultHost中使用不同的值<Engine>,这就是 Tomcat 将查找的目录结构。
Finally, for the ...tomcat\portion of the files you listed, Tomcat uses the dir from the $CATALINA_BASEenvironment variable. If that's not set, then it uses the dir from the $CATALINA_HOMEenvironment variable, which is the directory of the Tomcat installation. I like to set and use $CATALINA_BASEso that I don't "pollute" my Tomcat installation.
最后,对于...tomcat\您列出的文件部分,Tomcat 使用$CATALINA_BASE环境变量中的目录。如果未设置,则它使用$CATALINA_HOME环境变量中的目录,即 Tomcat 安装目录。我喜欢设置和使用,$CATALINA_BASE以免“污染”我的 Tomcat 安装。
回答by jeph perro
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 deploymentif you alter this after initial deployment, I don't think that has any effect
- tomcat/conf/context.xml 是“默认”context.xml,其内容与 webapp 上下文定义重叠。我的 TC 5 默认 context.xml 几乎没有任何内容,除了将 web.xml 列为受监视的资源之外,它支持这个概念。
- tomcat/Catalina//.xml 用于 web 应用程序。要么手动放置在这里,要么在部署时从您的 web 应用程序中获取……所以这是 TC 使用的真正主控。如果您编辑此更改,将在下次启动时读取。
- Tomcat的/ webapps /下的myapp / META-INF / context.xml的-这是复制到Tomcat的/卡塔利娜/在初始部署,如果你改变这个初始部署后,我不认为有任何影响
回答by James Schek
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).
其中#2 是最后一个应用(因此它的设置会覆盖所有以前的设置,如果适用)。
I have never used the webapp named context files (your option #2).
我从未使用过 webapp 命名的上下文文件(您的选项 #2)。

