Eclipse WTP has an option "Serve modules without publishing" that works well with tc6, but not with tc7. After investigation by the WTP team, there seem to be no way for them to fix this without modifying tomcat. The problem in WTP is reported here : https://bugs.eclipse.org/bugs/show_bug.cgi?id=333102 Basically, their DirContext implementation (org.eclipse.jst.server.tomcat.loader.WtpDirContext) returns a ResourceAttributes that correctly points to an existing location, but org.apache.catalina.loader.WebappClassLoader.findResourceInternal(String, String) ignores it and returns a ResourceEntry whose codeBase and source fields point to a non-existing location. This breaks applications that call getResource(...) on the Thread ContextClassLoader and use the returned URL. A call to getResourceAsStream(...) on the Thread CCL is OK.
I'm preparing a patch for org.apache.catalina.loader.WebappClassLoader.findResourceInternal(String, String) but I'm also wondering if tomcat should not provide such a "virtual" DirContext just like org.apache.catalina.loader.VirtualWebappLoader is provided (which could probably be used by WTP instead of org.eclipse.jst.server.tomcat.loader.WtpWebappLoader)
With aliases and altDirContexts this code is already pretty messy. A virtual DirContext may make things worse.
fixed WebappClassLoader in r1163802, will be available in tomcat 7.0.22
Not sure about the expected behavior of the WepappClassLoader, but here's something I ran into while testing the new release 7.0.22. I'm still experiencing the issue when using org.apache.catalina.loader.WebappClassLoader.findResources(String). Unlike org.apache.catalina.loader.WebappClassLoader.findResource(String), it doesn't look for resources into the local repository using org.apache.catalina.loader.WebappClassLoader.findResourceInternal(String, String), where the fix to this bug can be found. Not sure if this is an expected behavior, but this use case doesn't seem to be covered by the fix.
you're correct, my fix is not sufficient, I'll work on it soon. Unfortunately the code in tomcat is quite complex and feels like it has a lot of history, I have to be very careful not to break anything...
Thank you very much !
Sylvain, Thanks for your work on this. I've verified the "<classloader>.getResource()" is fixed in Tomcat 7.0.22 for "Serve modules without publishing". Unfortunately, the testing revealed I missed a change to DirContextURLConnection in 7.0.21 which breaks annotation processing for 3.0 webapps. See Eclipse bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=360012 This means that WTP 3.2.5, 3.3.2, or 3.4 will be needed to avoid the annotation problem in a released WTP. An updated org.eclipse.jst.server.tomcat.runtime.70.loader.jar is available in the bug above which fixes the problem. Until those releases are available, the simplest way to work around if you are using a 3.0 webapp is to edit the org.eclipse.jst.server.tomcat.core plug-in jar to replace the ".70.loader" jar with the updated one. Finally, I've updated the project set I use for testing to include a test for "<classloader>.getResources()". I'll try to clean it up some and attach a zip to the Eclipse bug in case you or someone else wants to use it. Cheers, Larry
I'm still working on a patch... Actually, I think that it's really impossible to have a custom DirContext that fakes WEB-INF/classes to allow multiple virtual paths because one way or another it would return inexistent URLs. So, I started to work on a patch that would allow to specify additional paths that should be searched for annotated classes just like WEB-INF/classes. Such a configuration parameter is located on the StandardContext. With this patch, WTP could totally avoid to provide its own extensions to tomcat classes and just configure a <Context> with the new property, a <Resource> with the org.apache.naming.resources.VirtualDirContext implementation and a <Loader> with the org.apache.catalina.loader.VirtualWebappLoader implementation.
I agree to release under the Apache Licence my changes to WtpDirContext found in the Eclipse WTP source. These changes extended the source that Fabrizio Giustina originally contributed to both Eclipse and Tomcat.
patch commited on trunk : 1209686 + 1209694 + 1209731 I'll apply to tc 7 in a couple of days
applied on tc7, will be available in 7.0.24.
Note that the patch to ContextConfig contained invalid assumptions that triggered regressions (see bug 52669). Namely: - the patch assumed that web applications were always deployed in exploded form - the patch assumed that classes were always located in packages The patch also broke OSGi embedded usage.
See r1307600 for one more issue with the patch. The fix will be in 7.0.27.