java Tomcat context.xml 文件,有层次吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/318241/
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
Tomcat context.xml files, is there a hierarchy?
提问by jeph perro
I am trying to use symbolic links in one of the applications I have running on Tomcat5. Thanks to some help from another StackOverflow questionI was able to do it by creating a context.xml file in
我正在尝试在我在 Tomcat5 上运行的应用程序之一中使用符号链接。感谢另一个 StackOverflow 问题的帮助,我能够通过在
/...myapplication/META-INF/context.xml
/...myapplication/META-INF/context.xml
I am now trying to implement this on a production server. However, there are other applications running on it. And there is another context file
我现在正在尝试在生产服务器上实现这一点。但是,还有其他应用程序在其上运行。还有另一个上下文文件
/...tomcat/conf/context.xml
/...tomcat/conf/context.xml
It seems to me these are setting configurations server-wide to all applications. If I allowLinks in the conf/context.xml file, my symbolic links work. If I don't allowLinks in conf/context.xml, my application's symbolic links do not work, even though I have allowed them in the META-INF/context.xml
在我看来,这些是为所有应用程序设置服务器范围内的配置。如果我在 conf/context.xml 文件中允许链接,我的符号链接就起作用了。如果我不允许 conf/context.xml 中的链接,即使我在 META-INF/context.xml 中允许它们,我的应用程序的符号链接也不起作用
My question is, does the conf/context.xml control all applications? If I want symbolic links to work only in one application, do I need to remove the conf/context.xml and create new context files for each application? Or is there a way I can allow symbolic links in myapplication only?
我的问题是,conf/context.xml 控制所有应用程序吗?如果我希望符号链接仅在一个应用程序中工作,是否需要删除 conf/context.xml 并为每个应用程序创建新的上下文文件?或者有没有一种方法可以只在我的应用程序中允许符号链接?
回答by netjeff
See my answerto the "Which Tomcat 5 context file takes precedence" question.
请参阅我对“哪个 Tomcat 5 上下文文件优先”问题的回答。
Regarding your specific allowLinksquestion, the value in conf/context.xmltakes precedence by default. If you say nothing in your conf/context.xml, the default value is allowLinks="false"in your conf/context.xml.
关于您的具体allowLinks问题,conf/context.xml默认情况下,值优先。如果你什么都没说conf/context.xml,默认值allowLinks="false"在你的conf/context.xml.
If you want to change it only for your myapplication, trying to say <Context allowLinks="true" ...>in your META-INF/context.xmlwill have no effect because normallythe conf/context.xmlsetting will take precedence.
如果你想改变它,只为你myapplication,想说<Context allowLinks="true" ...>你META-INF/context.xml不会有任何影响,因为通常的conf/context.xml设置将优先。
But, if you say <Context allowLinks="true" override="true"...> in your META-INF/context.xml, then all your <Context>settings in META-INF/context.xmlwill be highestprecedence, overriding anything in conf/context.xml.
但是,如果你说你的,那么你所有的设置,在将最高优先级,它将覆盖任何东西。<Context allowLinks="true" override="true"...> META-INF/context.xml<Context>META-INF/context.xmlconf/context.xml
Finally, instead of a myapplication/WEB-INF/context.xmlfile, I recommend using a conf/Catalina/localhost/myapplication.xmlfile. This technique means you can keep the contents of your WEB-INF clean, which is the guts of your webapp -- I don't like to risk mucking about in the guts of my webapp. :-)
最后,myapplication/WEB-INF/context.xml我建议使用conf/Catalina/localhost/myapplication.xml文件而不是文件。这种技术意味着您可以保持 WEB-INF 的内容干净,这是您的 web 应用程序的内脏——我不喜欢冒险在我的 web 应用程序内脏。:-)
回答by jeph perro
Just to add a point.
只是补充一点。
Usually th meta-inf/context.xml is copied to the conf/Catalina/localhost/myapplication.xml
通常将 meta-inf/context.xml 复制到 conf/Catalina/localhost/myapplication.xml
When redploying a war file the conf/Catalina/localhost/myapplication.xml is deleted and a new one copied in as described above.
当重新部署一个 war 文件时,conf/Catalina/localhost/myapplication.xml 被删除,并如上所述复制一个新的。
This can be a real pain. I like the idea of application specific context but I fail to see how having this in the meta-inf directory helps.
这可能是一个真正的痛苦。我喜欢应用程序特定上下文的想法,但我看不出在 meta-inf 目录中有什么帮助。
For Prod, UAT, etc this becomes a real pain.
对于 Prod、UAT 等来说,这真的很痛苦。
So for anything server static but application specific it is better to put it in the conf/context.xml. Which has the negative that it holds context for several applications, touch one you inadvertently touch them all.
因此,对于任何服务器静态但特定于应用程序的内容,最好将其放在 conf/context.xml 中。其不利之处在于它包含多个应用程序的上下文,触摸一个您会不经意地触摸它们。

