Re: Opening files, relative paths

2001-04-02 Thread Incze Lajos

On Mon, Apr 02, 2001 at 11:48:42AM -0500, Allen Walker wrote:
> What I'm doing is this:
> 
> java.io.File xmlfile = new java.io.File (path_to_file).
> 
> Problem is, I don't know how to specify the var path_to_file other than the 
> absolute path. I find the relative path to be /jakarta-tomcat/bin, but this 
> obviously isn't where I wish to place my app config files etc. Coding 
> absolute path's is troublesome due to deployment issues. Any help appreciated.
> 
> Thanks
> -allen-
> 

You can use the ServletContext's getRealPath( context_relative_path )
method. E.g.: servletContext.getRealPath( "/WEB-INF/myconf.xml" ).
  incze



Re: Opening files, relative paths

2001-04-02 Thread Craig R. McClanahan



On Mon, 2 Apr 2001, Incze Lajos wrote:

> On Mon, Apr 02, 2001 at 11:48:42AM -0500, Allen Walker wrote:
> > What I'm doing is this:
> > 
> > java.io.File xmlfile = new java.io.File (path_to_file).
> > 
> > Problem is, I don't know how to specify the var path_to_file other than the 
> > absolute path. I find the relative path to be /jakarta-tomcat/bin, but this 
> > obviously isn't where I wish to place my app config files etc. Coding 
> > absolute path's is troublesome due to deployment issues. Any help appreciated.
> > 
> > Thanks
> > -allen-
> > 
> 
> You can use the ServletContext's getRealPath( context_relative_path )
> method. E.g.: servletContext.getRealPath( "/WEB-INF/myconf.xml" ).
>   incze
> 

This approach works -- but *only* if your web application is expanded into
a real directory (instead of being run directly from the WAR file).  To
access a properties file within the WAR, no matter what your servlet
container does, do something like this:

InputStream is =
  getServletContext().getResourceAsStream("/WEB-INF/web.xml");

which will let you read the web application's deployment descriptor.  You
can use any context-relative path that you wish.

Craig McClanahan