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

时间:2014-05-21 03:06:33

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

我使用Eclipse WTP Tomcat创建了一个名为“test”的Dynamic Web Projects,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(网络上下文)不在< CATALINA_HOME> / webapps(这是appBase的默认值)中,并且:
  2. 通过编写< Context>来配置Webapp。 < CATALINA_HOME> \ conf \ server.xml中< Host>下的元素元件。
  3. 以下是< 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是&lt; WatchedResource&gt;在&lt; CATALINA_HOME&gt; \ conf \ context.xml中默认情况下,我尝试添加&lt; WatchedResource&gt;以下每种格式的元素仍然不起作用:

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

    HERE是其他有效的配置方式:

    1. 使用单独的文件&lt; CATALINA_HOME&gt; \ conf \ Catalina \ localhost \ test.xml配置上下文,或者:
    2. 在没有任何其他配置的情况下将“test”移动到&lt; CATALINA_HOME&gt; \ webapps,或者:
    3. 检查Eclipse WTP中的“服务器选项”中的“未发布服务模块”

2 个答案:

答案 0 :(得分:3)

<WatchedResoucre>仅适用于从server.xml部署上下文时未使用的自动部署功能。

答案 1 :(得分:-2)

重新加载仅在我更新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