You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Allen Walker <aw...@mail.utexas.net> on 2001/04/02 18:48:42 UTC
Opening files, relative paths
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-
Re: Opening files, relative paths
Posted by "Craig R. McClanahan" <cr...@apache.org>.
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
Re: Opening files, relative paths
Posted by Incze Lajos <in...@mail.matav.hu>.
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