tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject RE: Accessing a packaged file
Date Sat, 16 Jun 2001 04:16:36 GMT

On Tue, 24 Apr 2001, Milt Epstein wrote:

> On Mon, 23 Apr 2001, Filip Hanik wrote:
> > > In this case, the class and the resource were packaged together:
> > > that should mean you could use the same class-loader for both, no?
> > > (Assuming, of course, the user didn't monkey around with your
> > > classes,...)
> >
> > this may however not be guaranteed at all times. especially if you
> > monkey:ed around with your classpath, hence it is safer to use the
> > context class loader instead.  that way you don't have to worry,
> > better to play it safe, don't you agree?
> Once again, I ask, what is the difference between the
> Class/ClassLoader getResource* methods and the ServletContext ones?
> Thanks.

This didn't get answered in April, but it's worth an answer for the

The ServletContext.getResource() methods are used to access static
resources from your web application.  For example, if you want to read the
web.xml file for your own app, the portable way to do this is:

  InputStream stream =

On the other hand, Class.getResource* (and therefore
ClassLoader.getResource*) are used to load resource files from the class
path for your web application (i.e. from unloaded files in
/WEB-INF/classes or inside a JAR file in /WEB-INF/lib).

Craig McClanahan

View raw message