You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mike Bremford <to...@big.faceless.org> on 2001/11/11 02:01:39 UTC

ClassLoader woes in Tomcat 4.01

Hi all

I'm trying to load a resource from a JAR which I have placed in
$TOMCAT_HOME/lib, but I can't seem to be able to access it from Tomcat
4. Works fine from an Application or Tomcat 3.2

The symptoms are when I call
ClassLoader.getSystemResource("/path/to/myresource"), I get null. It is
definately there. The JAR isn't signed, there's no other unusual stuff
going on. I'm calling this from inside a Filter if it makes a
difference.

Any ideas? If it helps the URL returned when I try this from an
application is "jar:file:/home/mike/blah/myapp.jar!/path/to/myresource"


Cheers... Mike

--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: ClassLoader woes in Tomcat 4.01 (IGNORE)

Posted by Mike Bremford <to...@big.faceless.org>.
Sorry to follow myself up, but my bad.

I see now that
Thread.currentThread().getContextClassLoader().getResource() is the
method I should have been calling, which works fine.

Cheers... Mike


Mike Bremford wrote:
> 
> Hi all
> 
> I'm trying to load a resource from a JAR which I have placed in
> $TOMCAT_HOME/lib, but I can't seem to be able to access it from Tomcat
> 4. Works fine from an Application or Tomcat 3.2
> 
> The symptoms are when I call
> ClassLoader.getSystemResource("/path/to/myresource"), I get null. It is
> definately there. The JAR isn't signed, there's no other unusual stuff
> going on. I'm calling this from inside a Filter if it makes a
> difference.
> 
> Any ideas? If it helps the URL returned when I try this from an
> application is "jar:file:/home/mike/blah/myapp.jar!/path/to/myresource"
> 
> Cheers... Mike
> 
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>

--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: ClassLoader woes in Tomcat 4.01

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Sun, 11 Nov 2001, Mike Bremford wrote:

> Date: Sun, 11 Nov 2001 02:01:39 +0100
> From: Mike Bremford <to...@big.faceless.org>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: tomcat-user@jakarta.apache.org
> Subject: ClassLoader woes in Tomcat 4.01
>
> Hi all
>
> I'm trying to load a resource from a JAR which I have placed in
> $TOMCAT_HOME/lib, but I can't seem to be able to access it from Tomcat
> 4. Works fine from an Application or Tomcat 3.2
>
> The symptoms are when I call
> ClassLoader.getSystemResource("/path/to/myresource"), I get null. It is
> definately there. The JAR isn't signed, there's no other unusual stuff
> going on. I'm calling this from inside a Filter if it makes a
> difference.
>
> Any ideas? If it helps the URL returned when I try this from an
> application is "jar:file:/home/mike/blah/myapp.jar!/path/to/myresource"
>

If you call ClassLoader.getSystemResource(), you are asking for the
resource to be loaded from the *system* class loader, which is a parent of
the class loader that deals with $TOMCAT_HOME/lib.  It works in Tomcat 3.2
because the class loader architecture is different -- the system class
loader in 3.2 contains these JARs.  Use ClassLoader.getResource() instead,
and you will be much happier.


For more information on how class loaders are configured in Tomcat 4, see:

  http://jakarta.apache.org/tomcat/tomcat-4.0-doc/class-loader-howto.html

>
> Cheers... Mike
>

Craig McClanahan


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>