我正在尝试在 Tomcat5 上运行的应用程序之一中使用符号链接。 感谢另一个 StackOverflow 问题的帮助,我能够做到这一点
中创建 context.xml 文件,
通过在/...myapplication/META-INF/context.xml
我现在尝试在生产服务器上实现此功能。 但是,还有其他应用程序在其上运行。 还有另一个上下文文件
/...tomcat/conf/context.xml
在我看来,这些是在服务器范围内向所有应用程序设置配置。 如果我在 conf/context.xml 文件中允许链接,我的符号链接就会起作用。 如果我不允许conf/context.xml中的链接,我的应用程序的符号链接将不起作用,即使我已在META-INF/context.xml中允许它们
我的问题是,conf/context.xml是否控制所有应用程序? 如果我希望符号链接仅在一个应用程序中工作,是否需要删除 conf/context.xml 并为每个应用程序创建新的上下文文件? 或者有没有办法只允许在我的应用程序中使用符号链接?
I am trying to use symbolic links in one of the applications I have running on Tomcat5. Thanks to some help from another StackOverflow question I was able to do it
by creating a context.xml file in
/...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
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
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?
发布评论
评论(2)
请参阅我对“哪个 Tomcat 5 上下文文件优先”问题。
关于您的特定
allowLinks
问题,默认情况下,conf/context.xml
中的值优先。 如果您在conf/context.xml
中未指定任何内容,则默认值为allowLinks="false"
在您的conf/context.xml
中。如果您只想为您的
myapplication
更改它,请尝试在META-INF/ 中说
将不起作用,因为通常
context.xmlconf/context.xml
设置将优先。但是,如果您说override="true" ...>
在您的
META-INF/context.xml
中,然后您的所有
设置在META-INF/context.xml
中> 将具有最高优先级,覆盖conf/context.xml
中的任何内容。最后,我建议使用
conf/Catalina/localhost/myapplication.xml
文件,而不是myapplication/WEB-INF/context.xml
文件。 这种技术意味着你可以保持 WEB-INF 的内容干净,这是你的 web 应用程序的核心——我不想冒险破坏我的 web 应用程序的核心。 :-)See my answer to the "Which Tomcat 5 context file takes precedence" question.
Regarding your specific
allowLinks
question, the value inconf/context.xml
takes precedence by default. If you say nothing in yourconf/context.xml
, the default value isallowLinks="false"
in yourconf/context.xml
.If you want to change it only for your
myapplication
, trying to say<Context allowLinks="true" ...>
in yourMETA-INF/context.xml
will have no effect because normally theconf/context.xml
setting will take precedence.But, if you say
<Context allowLinks="true" override="true" ...>
in yourMETA-INF/context.xml
, then all your<Context>
settings inMETA-INF/context.xml
will be highest precedence, overriding anything inconf/context.xml
.Finally, instead of a
myapplication/WEB-INF/context.xml
file, I recommend using aconf/Catalina/localhost/myapplication.xml
file. 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. :-)只是补充一点。
通常,meta-inf/context.xml 会被复制到conf/Catalina/localhost/myapplication.xml
当重新部署一个war 文件时,conf/Catalina/localhost/myapplication.xml 会被删除,并按照上面的描述复制一个新的。
这可能是一个真正的痛苦。 我喜欢应用程序特定上下文的想法,但我不明白将其放在 meta-inf 目录中有何帮助。
对于 Prod、UAT 等来说,这真的很痛苦。
因此,对于任何服务器静态但特定于应用程序的内容,最好将其放在 conf/context.xml 中。 其缺点是它保存了多个应用程序的上下文,触摸其中一个您就会无意中触摸所有应用程序。
Just to add a point.
Usually th meta-inf/context.xml is copied to the 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.
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.
For Prod, UAT, etc this becomes a real pain.
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.