tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wade Chandler <wchand...@redesetgrow.com>
Subject Re: weird tomcat5.0.30 behaviour with jar in WEB-INF/classes
Date Wed, 01 Dec 2004 16:06:11 GMT
Simone Pierazzini wrote:
> On Wed, 01 Dec 2004 09:49:33 -0500, Wade Chandler
> <wchandler@redesetgrow.com> wrote:
> 
> 
>>I never try to use relative paths in getResource.  I always do this
>>getResource("/pippo.jar");  Also, I usually pick a class in my package
>>that I know will certainly be in my web-app classes folder or one of
>>it's jars.  This way the classloader used for my call will know about my
>>objects and classes at it's level....so it doesn't make delegate
>>calls...and I use com.mydomain.mypackage.MyClass.class.getResource
>>instead of using the classloader call though that should not matter....
> 
> 
> asking resources to classes or classloaders is the same thing:
> absolute paths for classes are relative paths for classloaders so the
> following lines are equivalent:
> 
> com.mydomain.mypackage.MyClass.class.getResource("/xx.txt")
> com.mydomain.mypackage.MyClass.class.getClassLoader().getResource("xx.txt")
> 
> I pick a class in my package too: if you pick another class you don't
> know which classloader you 're using (common/shared/ etc.)
> 
> bye
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> 

Right, thought you were creating your own URLClassLoader instance to 
locate your jars dynamically (not getting the current).  Barring that 
and looking at your post and then looking at one of Yoavs, then my guess 
is the ClassLoader in tomcat is for what ever reason doing something like:
if( name.endsWith(".jar") )
{
    //resolve to the home work dir.
}

regardless of the directory being lib or classes....seems like a bug to 
me as any file in the classpath should just be a file as a jar file 
should have to be added to the classpath like it's a directory.

Anyways, are the file names hard coded in your app?  You can always come 
up with your own file name extension to work around the issue I suppose. 
  A jar is a jar by any other name .zip, .foo, .mar (?)  What ever...the 
point I guess is the class loader for what ever reason is resolving on 
purpose the .jar ext instead of checking first if the file is under lib 
or a sub dir.  So you should be able to just rename the file ext unless 
for some reason you have an app that has to have the .jar on the end. 
The jar classes should still work against files with different ext.

Wade


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message