哪个 Tomcat 5 上下文文件优先?

发布于 2024-07-09 14:56:12 字数 437 浏览 7 评论 0原文

Tomcat 文档 说:

上下文描述符的位置是;

$CATALINA_HOME/conf/[引擎名]/[主机名]/context.xml
$CATALINA_HOME/webapps/[webappname]/META-INF/context.xml

在我的服务器上,我至少有 3 个文件:

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

优先级顺序是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情绪失控 2024-07-16 14:56:12

对于您列出的文件,假设您使用所有默认值,简单的答案是,顺序是(注意 conf/Catalina/localhost):

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

我将此(以及以下讨论)基于上下文容器的 Tomcat 5.5 官方文档。

那么,如果这是简单的答案,那么完整的答案是什么?

雄猫 5.5。 除了您列出的元素之外,还将在其他几个地方查找 元素(请参阅官方文档)。

如果 Tomcat 找到 Catalina/localhost/myapp.xml,则 META-INF/context.xml 将永远不会打开。 因此,如果您实际上拥有上述所有文件,更正确的说法是 META-INF/context.xml不相关,而不是说它是最低优先级。

如果您在 Catalina/localhost/myapp.xml 中输入 ,这将使其成为最高conf/context.xml 为何。 只要您没有 Catalina/localhost/myapp.xml (请参阅上一段),您的 META-INF\context.xml 中也会有同样的情况。

此外,上面文件中路径的 /Catalina/localhost/ 部分实际上来自“默认”conf/server.xml 并与 < 匹配;引擎名称=“Catalina”defaultHost=“localhost”>。 如果您的 server.xml 中对 namedefaultHost 使用不同的值,则该目录是Tomcat 将查找的结构。

最后,对于列出的文件的 ...tomcat\ 部分,Tomcat 使用 $CATALINA_BASE 环境变量中的目录。 如果未设置,则会使用 $CATALINA_HOME 环境变量中的目录,即 Tomcat 安装目录。 我喜欢设置和使用 $CATALINA_BASE 这样我就不会“污染”我的 Tomcat 安装。

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.

錯遇了你 2024-07-16 14:56:12

我的理解是:

  • tomcat/conf/context.xml 是“默认”context.xml,其内容覆盖有 webapp 上下文定义。 我的 TC 5 默认 context.xml 中几乎没有任何内容,除了将 web.xml 列为受监视资源(支持此概念)。
  • tomcat/Catalina//.xml 用于 web 应用程序。 它要么手动放置在这里,要么在部署时从您的网络应用程序中获取......所以这是 TC 使用的真正主控。 如果您编辑此更改,则会在下次启动时读取。
  • tomcat/webapps/myapp/META-INF/context.xml - 在初始部署时将其复制到 tomcat/Catalina/ 如果您在初始部署后更改它,我认为这不会产生任何影响

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
池予 2024-07-16 14:56:12

我没有找到任何官方文档,但我观察到加载顺序是:

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

其中 #2 是最后应用的一个(因此它的设置会覆盖所有先前的设置(如果适用))。

我从未使用过名为上下文文件的 Web 应用程序(您的选项#2)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文