You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Aaron Hamid <ar...@cornell.edu> on 2005/11/09 21:19:32 UTC
Subtlety in WebappClassLoader wrt to leading '/'
Hi all,
I have searched bugzilla, and the tc-users and tc-dev lists on MARC, as well as the source code, so hopefully this is vetted enough for this list (I have NOT posted a bug).
It appears that WebappClassLoader (in at least versions 5.0.28 and 5.5.12 which I have looked at) will accept a leading slash '/' on the resource path parameter to the 'getResource*()' calls. This implicit support appears to be due to the File and URI/URL APIs it uses to resolve the resource.
While it is intuitive to me to support a leading slash, Sun's application class loader behavior is different. Resource paths with leading slashes are not found. When the slash is removed they are found. I could not find any mention of these semantics in the standard ClassLoader (not Class, I am aware of how Class.getResource differs) documentation, however a quick Google search will confirm the notion that ClassLoader will not find resources with leading slashes (at least one old post on tomcat-dev: http://mail-archives.apache.org/mod_mbox/tomcat-dev/200108.mbox/%3C3B7854FF.2FA71171@apache.org%3E quote at bottom).
I raise this issue because I just spent a lot of time debugging a problem where a certain resource WAS found in Tomcat, but was not found when running JUnit tests from Ant or from within Eclipse. Ultimately it was my fault for prepending a slash, but I wonder if it is worth either matching Sun's behavior, or documenting this somewhere (and again, I may have missed it).
Aaron Hamid
CIT/ATA
Cornell University
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org