3
votes

I have created a Dynamic Web Projects named "test" using Eclipse WTP Tomcat, Eclipse version is Java EE Kepler Service Release 2, Tomcat version is 7.0.53, Servlet 3.0, Win 8.1 x86, jdk 1.6.0_45, but after several tries, I found the problem occurs when matching all the following conditions:

  1. the Webapp(web context) is not in <CATALINA_HOME>/webapps(which is the default value of appBase) and:
  2. the Webapp is configured by writing a <Context> element in <CATALINA_HOME>\conf\server.xml, under the <Host> element.

Here is part of <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>

and here is the Directory Structure of "test":

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

Although WEB-INF/web.xml is <WatchedResource> in <CATALINA_HOME>\conf\context.xml by default, I tried to add a <WatchedResource> element in each of the following formats, still not works:

<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 is other configuration ways that works:

  1. use a seperate file <CATALINA_HOME>\conf\Catalina\localhost\test.xml to configure context, or:
  2. move "test" into <CATALINA_HOME>\webapps without any more configuration, or:
  3. check "Serve modules without publishing" of Server Options in Eclipse WTP
2
Exactly where did you add those <WatchedResource> elements?Mark Thomas
@MarkThomas , I tried thoses <WatchedResource> elements one by one under <Context> element in conf/server.xml, but no one did work!user3658924
And you restarted Tomcat after each change to server.xml?Mark Thomas
@MarkThomas , Yes, I did restart. I know the main conf/server.xml file cannot be reloaded without restarting Tomcat. I will check if this problem occurs under Linux.user3658924
@MarkThomas , I tested under Ubuntu with the same Tomcat version, it behaviors same as that under Windows. I also tested again with Tomcat 7.0.8, and did not work either. It seems to be a bug?user3658924

2 Answers

5
votes

<WatchedResoucre> only works with the automatic deployment feature which is not used when Contexts are deployed from server.xml.

-2
votes

Reload worked only after I updated the server.xml file!!!

By setting the 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