tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitry Sklyut <>
Subject RE: Problem reading resource file in WEB-INF\lib
Date Thu, 15 May 2003 18:18:23 GMT
For web apps I found it useful to do:


That way you know that you are using the correct classloader (the one that
loaded the object) to pull up your resource not the default one


-----Original Message-----
From: Jonathan Tiu []
Sent: Thursday, May 15, 2003 2:09 PM
To: 'Tomcat Users List'
Subject: RE: Problem reading resource file in WEB-INF\lib

I think the problem is the line "invdat.getClass ()". It returns the class
object for String.

If you look at the definition of that method:

public InputStream getResourceAsStream(String name) {
        name = resolveName(name);
        ClassLoader cl = getClassLoader0();
        if (cl==null) {
            // A system class.
            return ClassLoader.getSystemResourceAsStream(name);
        return cl.getResourceAsStream(name);

it will call getSystemResourceAsStream () (since String class is considered
a system class since it's loaded by the bootstrap classloader)

So that means the system classloader is invoked.  Now is the system
the same as the (Tomcat) webapp loader...?? The webapp loader would be able
to find WEB-INF\lib right?

-----Original Message-----
From: Jonathan Tiu 
Sent: May 15, 2003 10:52 AM
To: 'Tomcat Users List'
Subject: RE: Problem reading resource file in WEB-INF\lib

It attempts to load the resource file ( like this:

String invdat = "/com/ibm/icu/impl/data/";
InputStream i = invdat.getClass().getResourceAsStream(invdat);
BufferedInputStream b = new BufferedInputStream(i, 110000);

is it that it uses a classloader that isn't looking in WEB-INF\lib??

-----Original Message-----
From: Shapira, Yoav []
Sent: May 15, 2003 10:03 AM
To: Tomcat Users List
Subject: RE: Problem reading resource file in WEB-INF\lib

Can you see what the code in icu4j.jar looks like?  Specifically, which
way does it load the resource?

Yoav Shapira
Millennium ChemInformatics

>-----Original Message-----
>From: Jonathan Tiu []
>Sent: Thursday, May 15, 2003 12:50 PM
>To: ''
>Subject: Problem reading resource file in WEB-INF\lib
>This is really stumping me so any help would be much appreciated!
>I have a simple web app, called Foo, on Tomcat that makes use of a jar
>called icu4j.jar (IBM ICU library). The jar is
>in the lib directory
>ie.  Foo\WEB-INF\lib\icu4j.jar
>My application fails because it makes a call into the icu library
which, in
>turn, attempts to load a resource file  which is also in the icu4j.jar.
>But the class loader seems to fail loading the resource file. I guess
>can't find it.
>I have read the Tomcat documentation on class loading, etc. and it
>"For classes and resources specific to a particular web application,
>unpacked classes and resources under /WEB-INF/classe of your web
>archive, or place JAR files containing those classes and resources
>/WEB-INF/lib of your web application archive"
>So I don't need to do anymore configuration to tell Tomcat where to
>resource file? I mean, the jar containing the file is in the classpath,
>I was it when my code is run, it invokes the system
>classloader which checks only the CLASSPATH and maybe doesn't check
>It isn't a bug in icu4j.jar because, running my java app outside of
>works perfectly fine.
>Thanks a lot!
>To unsubscribe, e-mail:
>For additional commands, e-mail:

This e-mail, including any attachments, is a confidential business
communication, and may contain information that is confidential, proprietary
and/or privileged.  This e-mail is intended only for the individual(s) to
whom it is addressed, and may not be saved, copied, printed, disclosed or
used by anyone else.  If you are not the(an) intended recipient, please
immediately delete this e-mail from your computer system and notify the
sender.  Thank you.

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

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

NOTICE:  This communication may contain proprietary or other confidential
business information of Orcom Solutions, Inc.  If you are not the intended
recipient or believe that you may have received this communication in error,
please reply to the sender indicating that fact and delete the copy you
received.  In addition, you should not print, copy, retransmit, disseminate,
or otherwise use the information.  Thank you.  

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message