My webapp is placed outside CATALINA_BASE/webapps. I put my context.xml into CATALINA_BASE/conf/Catalina/localhost. My context.xml looks like: <Context docBase="/somedir/mywebapp"> <WatchedResource>WEB-INF/web.xml</WatchedResource> ...some other stuff... </Context> If I change web.xml my webapp will not be reloaded! If insert an absolute path <WatchedResource>/somedir/mywebapp/WEB-INF/web.xml</WatchedResource> it works, but to use absolute paths will become unhandy - especially when I try to put the WatchedResource stuff to defaultcontext.xml, because I have a lot of webapps not only one. If I put my webapp in CATALINA_BASE/webapps all works fine - but this is not a solution for me.
First, I'm changing this to an enhancement, as the current code is clearly designed for absolute paths so what you're reporting is not a bug. Second, the relevant code you want to look at is in org.apache.catalina.startup.HostConfig, the addWatchedResourced method. That method will loop over the declared WatchedResources for the Context and try to create a java.io.File corresponding to each WatchedResource for monitoring. As you can see from the code, it either wants an absolute path to the WatchedResource, or a docBase relative to which the WatchedResource can be found. I'm guessing in your case the docBase is relative, not absolute, so the method uses appBase as the context for docBase, and since your webapp is outside appBase this doesn't work. Is my guess right? Does it work if you make your docBase absolute?
(In reply to comment #1) > First, I'm changing this to an enhancement, as the current code is clearly > designed for absolute paths so what you're reporting is not a bug. I get my infos from documentation and not from the source - and in the docs I havn't found any info that you need absolute paths. > ... > I'm guessing in your case the docBase is relative, not absolute, so the method > uses appBase as the context for docBase, and since your webapp is outside > appBase this doesn't work. Is my guess right? Does it work if you make your > docBase absolute? My docBase is absolute like <Context docBase="${somedir}/appdir"> and ${somedir} is absolute like "c:/webapps". And it doesn't work with <WatchedResource>WEB-INF/web.xml</WatchedResource> in conf/context.xml, and it also doesn_t work with <WatchedResource>c:/webapps/appdir/WEB-INF/web.xml</WatchedResource> in conf/context.xml.
In my tests using tomcat 6.0.13, JDK 1.6, when the path in the WatchedResource is relative path, the absolute path interpreted by the code as written for the relative path will be an absolute path to relative to the JVM startup directory. Obviously something is very quirky in there. Since the path will then most likely point to an invalid resource, it will not be watched and there is no warning give to the user either. In this case addWatchedResource is given a 'null' docBase. The code in question is in HostConfig.deployDescriptor(). Suggested code improvements: o for descriptors that explicitly specify an absolute docBase, pass it to the addWatchedResource method instead of 'null' o print warning if watched resource evaluated path points to a resource that does not exist I came up with a fix but I was discouraged to not find any existing unit tests to verify regression. If there are any please tell me so I can verify the patch.
I would like to experiment with this patch. Do you think you can post it here for others to review and test?
Created attachment 21090 [details] patch that fixes HostConfig to comply with the documentation regarding docBase and watched resources I manufactured this patch against the official org/apache/catalina/startup/HostConfig.java file included with Tomcat 6.0.13. it is small enough such that recreating it to work with 5.5.x series releases should be trivial. Hope it helps.You may need to modify the patch header to apply it.
Thanks for patch, Look at http://svn.apache.org/viewvc?rev=613558&view=rev. I hope we can at the fix to next tomcat 6/55 release Peter
Thanks for applying it. I am not sure pero wants credit for the patch. I was the one who submitted the patch but the changes to the changelog seem to indicate that pero provided it. Changelog reads "Patch provided by Gernot Pfingstl (pero)" If the patch is applied, should the status stay 'NEW'
Fix added for Release 5.5.26 and 6.0.16!
I correct my mistake! Sorry Peter