You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jim Downing <ji...@pobox.com> on 2001/04/23 18:09:21 UTC

Accessing a packaged file

Hi,
I'm trying to get a servlet to access a text file that has been packaged
with the servlet in a .war file. Is it possible to access the file without
knowing it's absolute path when deployed, and if so how?

jim


RE: Accessing a packaged file

Posted by Fernando Padilla <fe...@interdimensions.com>.
you want to take a look at the

getServletContext().getResource*


methods.  These methods are implemented by the Servlet Container to allow
the servlet to access resources where ever they happend to be.. either
in a file, in a WAR file, in a database, however the container wants to
maintain it....

fernando




On Mon, 23 Apr 2001, Milt Epstein wrote:

> On Mon, 23 Apr 2001, Filip Hanik wrote:
>
> > Thread.currentThread().getContextClassLoader().getResourceAsStream
> >
> > picks up files in your WEB-INF/classes or WEB-INF/lib inside of a jar or zip
> [ ... ]
>
> I have seen this this construct mentioned a few times here:
>
> Thread.currentThread().getContextClassLoader().getResourceAsStream()
>
> but is this any different from:
>
> getContext().getResourceAsStream()
>
> (similar for getResource(), of course).
>
>
> > > -----Original Message-----
> > > From: Jim Downing [mailto:jimdowning@pobox.com]
> > > Sent: Monday, April 23, 2001 9:09 AM
> > > To: tomcat-user@jakarta.apache.org
> > > Subject: Accessing a packaged file
> > >
> > >
> > > Hi,
> > > I'm trying to get a servlet to access a text file that has been packaged
> > > with the servlet in a .war file. Is it possible to access the file without
> > > knowing it's absolute path when deployed, and if so how?
> > >
> > > jim
> > >
> > >
> >
>
> Milt Epstein
> Research Programmer
> Software/Systems Development Group
> Computing and Communications Services Office (CCSO)
> University of Illinois at Urbana-Champaign (UIUC)
> mepstein@uiuc.edu
>


RE: Accessing a packaged file

Posted by Milt Epstein <me...@uiuc.edu>.
On Mon, 23 Apr 2001, Filip Hanik wrote:

> Thread.currentThread().getContextClassLoader().getResourceAsStream
>
> picks up files in your WEB-INF/classes or WEB-INF/lib inside of a jar or zip
[ ... ]

I have seen this this construct mentioned a few times here:

Thread.currentThread().getContextClassLoader().getResourceAsStream()

but is this any different from:

getContext().getResourceAsStream()

(similar for getResource(), of course).


> > -----Original Message-----
> > From: Jim Downing [mailto:jimdowning@pobox.com]
> > Sent: Monday, April 23, 2001 9:09 AM
> > To: tomcat-user@jakarta.apache.org
> > Subject: Accessing a packaged file
> >
> >
> > Hi,
> > I'm trying to get a servlet to access a text file that has been packaged
> > with the servlet in a .war file. Is it possible to access the file without
> > knowing it's absolute path when deployed, and if so how?
> >
> > jim
> >
> >
>

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
mepstein@uiuc.edu


RE: Accessing a packaged file

Posted by Filip Hanik <ma...@filip.net>.
Thread.currentThread().getContextClassLoader().getResourceAsStream

picks up files in your WEB-INF/classes or WEB-INF/lib inside of a jar or zip
Filip

~
Namaste - I bow to the divine in you
~
Filip Hanik
Software Architect
filip@filip.net
www.filip.net

> -----Original Message-----
> From: Jim Downing [mailto:jimdowning@pobox.com]
> Sent: Monday, April 23, 2001 9:09 AM
> To: tomcat-user@jakarta.apache.org
> Subject: Accessing a packaged file
>
>
> Hi,
> I'm trying to get a servlet to access a text file that has been packaged
> with the servlet in a .war file. Is it possible to access the file without
> knowing it's absolute path when deployed, and if so how?
>
> jim
>
>