java 为什么对WEB-INF/web.xml的更改不会导致tomcat重新加载上下文?

62o28rlo  于 2023-02-11  发布在  Java
关注(0)|答案(3)|浏览(140)

我已经使用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上下文)不在<CATALINA_HOME>/webapps(appBase的默认值)中,并且:
  2. Webapp是通过 在<CATALINA_HOME>\conf\server.xml中的元素下写入一个元素来配置的。
    下面是<CATALINA_HOME>\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默认位于<CATALINA_HOME>\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.使用单独的文件<CATALINA_HOME>\conf\Catalina\localhost\test.xml配置上下文,或者:
1.将“test”移到<CATALINA_HOME>\webapps中而不进行任何配置,或者:
1.选中Eclipse WTP中服务器选项的“服务模块而不发布

83qze16e

83qze16e1#

您必须在context.xml中设置reloadable=“true”privileged=“true”,然后重新启动Tomcat服务器。

xmd2e60i

xmd2e60i2#

只有在我更新了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
5gfr0r5j

5gfr0r5j3#

<WatchedResoucre>仅适用于自动部署功能,当从server.xml部署上下文时不使用该功能。

相关问题