【问题标题】:Why changes to WEB-INF/web.xml does not cause tomcat to reload the context?为什么更改 WEB-INF/web.xml 不会导致 tomcat 重新加载上下文?
【发布时间】:2014-07-09 12:15:51
【问题描述】:

我使用 Eclipse WTP Tomcat 创建了一个名为“test”的动态 Web 项目,Eclipse 版本是 Java EE Kepler Service Release 2,Tomcat 版本是 7.0.53,Servlet 3.0,Win 8.1 x86,jdk 1.6.0_45,但之后尝试了几次,我发现匹配以下所有条件时会出现问题:

  1. Webapp(Web 上下文)不在 /webapps(这是 appBase 的默认值)中,并且:
  2. 通过在 \conf\server.xml 中的 元素下写入 元素来配置 Webapp。

这里是\conf\server.xml的一部分:

   <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>
    <Context docBase="D:/tmpdev/apache-tomcat-7.0.53/wtpwebapps/test" path="/test" reloadable="true"/>
  </Host>

这里是“test”的目录结构:

test
├─META-INF
│      MANIFEST.MF
│
└─WEB-INF
    │  web.xml
    │
    ├─classes
    │  └─test
    │          HelloServlet.class
    │          MyFilter1.class
    │          MyFilter2.class
    │          MyHttpSessionListener.class
    │          MyServletContextListener.class
    │
    └─lib

虽然WEB-INF/web.xml默认是\conf\context.xml中的,但我尝试在以下每种格式中添加一个元素,还是不行:

<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF\web.xml</WatchedResource>
<WatchedResource>D:/tmpdev/apache-tomcat-7.0.53/wtpwebapps/test/WEB-INF/web.xml</WatchedResource>
<WatchedResource>D:\tmpdev\apache-tomcat-7.0.53\wtpwebapps\test\WEB-INF\web.xml</WatchedResource>

这里是其他有效的配置方式:

  1. 使用单独的文件 \conf\Catalina\localhost\test.xml 来配置上下文,或者:
  2. 将“test”移动到 \webapps 而不进行任何配置,或者:
  3. 选中 Eclipse WTP 中服务器选项的“服务模块而不发布”

【问题讨论】:

  • 你在哪里添加了那些 元素?
  • @MarkThomas ,我在 conf/server.xml 中的 元素下一一尝试了那些 元素,但没有人起作用!
  • 你在每次更改 server.xml 后都重新启动了 Tomcat?
  • @MarkThomas ,是的,我确实重新启动了。我知道如果不重新启动 Tomcat,就无法重新加载主 conf/server.xml 文件。我会检查在Linux下是否会出现这个问题。
  • @MarkThomas ,我在 Ubuntu 下使用相同的 Tomcat 版本进行了测试,它的行为与 Windows 下的行为相同。我还用 Tomcat 7.0.8 再次测试,也没有工作。这似乎是一个错误?

标签: java eclipse tomcat web.xml eclipse-wtp


【解决方案1】:

仅在我更新 server.xml 文件后重新加载才有效!!!

通过设置 autoDeploy=true

<br>
The output from the logs then showed a "Reloading context" 

08-May-2018 20:58:56.654 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.reload <b>Reloading context </b>[/prototype_maven]
08-May-2018 20:58:56.654 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/prototype_maven] has started
08-May-2018 20:58:58.619 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
08-May-2018 20:58:58.629 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/prototype_maven] is completed

【讨论】:

    【解决方案2】:

    &lt;WatchedResoucre&gt; 仅适用于从 server.xml 部署上下文时不使用的自动部署功能。

    【讨论】:

      猜你喜欢
      • 2011-01-15
      • 2017-07-08
      • 1970-01-01
      • 2018-10-22
      • 2023-03-23
      • 2011-08-21
      • 2012-10-04
      • 2010-10-03
      • 1970-01-01
      相关资源
      最近更新 更多