Why changes to WEB-INF/web.xml does not cause tomcat to reload the context?
10,058
<WatchedResoucre>
only works with the automatic deployment feature which is not used when Contexts are deployed from server.xml.
Author by
user3658924
Updated on June 05, 2022Comments
-
user3658924 almost 2 years
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:
- the Webapp(web context) is not in <CATALINA_HOME>/webapps(which is the default value of appBase) and:
- 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 "%r" %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:
- use a seperate file <CATALINA_HOME>\conf\Catalina\localhost\test.xml to configure context, or:
- move "test" into <CATALINA_HOME>\webapps without any more configuration, or:
- check "Serve modules without publishing" of Server Options in Eclipse WTP
-
Mark Thomas almost 10 yearsExactly where did you add those <WatchedResource> elements?
-
user3658924 almost 10 years@MarkThomas , I tried thoses <WatchedResource> elements one by one under <Context> element in conf/server.xml, but no one did work!
-
Mark Thomas almost 10 yearsAnd you restarted Tomcat after each change to server.xml?
-
user3658924 almost 10 years@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 almost 10 years@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?