tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wade Chandler <>
Subject Re: weird tomcat5.0.30 behaviour with jar in WEB-INF/classes
Date Wed, 01 Dec 2004 14:49:33 GMT
Simone Pierazzini wrote:
> Hi,
> I use URLClassLoader to create class loaders that manage jars in WEB-INF/classes
> In WEB-INF/classes I have many jars that are incompatible each other
> (they have different classes with the same name inside).
> Suppose I want to load the following files as resources from a classLoader:
> - pippo.txt
> - pippo.jar
> In the first case I tried the line:
> classLoader.getResource("pippo.txt") 
> and correctly the returned URL was:
>  file:/ ... /myapp/WEB-INF/classes/pippo.txt
> where "..." stands for $CATALINA_HOME
> while, trying to get the second file:
> classLoader.getResource("pippo.jar")
> tomcat returned the following url:
>  file:/ ... /work/Catalina/localhost/myapp/loader/pippo.jar
> but the directory "... /work/Catalina/localhost/myapp/loader/" does
> not contain pippo.jar
> that is placed in  .../myapp/WEB-INF/classes/pippo.jar
> thanks in advance
> Simone Pierazzini
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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 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....

Maybe try to prepend a / to that file name.  Read the javadoc 
documentation for the method Class.getResource to understand the / 
before the name of the file.  Anyways, I always use the 
Class.getResource call as I mentioned above and I never have 
problems....I also am sure to use the / to make it an absolute 
classpath.  Read those java docs to understand more.

Hope you have some luck with that.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message