tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Tiu <Jonathan....@crystaldecisions.com>
Subject RE: Problem reading resource file in WEB-INF\lib
Date Thu, 15 May 2003 20:26:23 GMT
Right. But that only works if the object is not of a system class type.
In this case for a String class, doing

someString.getClass().getClassLoader() returns a null reference.


-----Original Message-----
From: Dmitry Sklyut [mailto:Dmitry_Sklyut@orcom.com]
Sent: May 15, 2003 11:18 AM
To: 'Tomcat Users List'
Subject: RE: Problem reading resource file in WEB-INF\lib


For web apps I found it useful to do:

someobject.getClass().getClassLoader().getResourceAsStream()

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

Dmitry

-----Original Message-----
From: Jonathan Tiu [mailto:Jonathan.Tiu@crystaldecisions.com]
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
classloader
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 (invuca.icu) like this:

String invdat = "/com/ibm/icu/impl/data/invuca.icu";
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 [mailto:Yoav.Shapira@mpi.com]
Sent: May 15, 2003 10:03 AM
To: Tomcat Users List
Subject: RE: Problem reading resource file in WEB-INF\lib



Howdy,
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 [mailto:Jonathan.Tiu@crystaldecisions.com]
>Sent: Thursday, May 15, 2003 12:50 PM
>To: 'tomcat-user@jakarta.apache.org'
>Subject: Problem reading resource file in WEB-INF\lib
>
>
>Hi!
>
>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
it
>can't find it.
>
>
>I have read the Tomcat documentation on class loading, etc. and it
says:
>
>"For classes and resources specific to a particular web application,
place
>unpacked classes and resources under /WEB-INF/classe of your web
>application
>archive, or place JAR files containing those classes and resources
under
>/WEB-INF/lib of your web application archive"
>
>So I don't need to do anymore configuration to tell Tomcat where to
find
>the
>resource file? I mean, the jar containing the file is in the classpath,
>right?
>I was thinking...is it when my code is run, it invokes the system
>classloader which checks only the CLASSPATH and maybe doesn't check
>WEB-INF\lib???
>
>It isn't a bug in icu4j.jar because, running my java app outside of
Tomcat,
>works perfectly fine.
>
>Thanks a lot!
>Jonathan
>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org

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



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.  



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