relative paths for properties files in a web app  
Author Message
Dundonald





PostPosted: 2007-10-3 4:47:00 Top

java-programmer, relative paths for properties files in a web app I want to plug an API in to a web app. The API has a properties file
that has properties defining the relative location of particular
files. The questions I have are

1. where should I store such 'particular files', indeed including the
properties file itself - should I manually load them in to the WEB-INF
directory?

and

2. how do I relatively relate to the path of the files located inside
the web app (for example in the WEB-INF) inside the properties file.

I hope that makese sense.

Thanks

 
Manish Pandit





PostPosted: 2007-10-3 7:31:00 Top

java-programmer >> relative paths for properties files in a web app On Oct 2, 1:46 pm, Dundonald <email***@***.com> wrote:
> I want to plug an API in to a web app. The API has a properties file
> that has properties defining the relative location of particular
> files. The questions I have are
>
> 1. where should I store such 'particular files', indeed including the
> properties file itself - should I manually load them in to the WEB-INF
> directory?
>
> and
>
> 2. how do I relatively relate to the path of the files located inside
> the web app (for example in the WEB-INF) inside the properties file.
>
> I hope that makese sense.
>
> Thanks

The property file can reside as an application resource in the
classpath. Read up on Resource Bundles in Java for more information
(including APIs like Class.getResourceAsStream()). As far as the path
goes, the files can stay under WEB-INF if they are not be served
directly to the browsers (via HTTP GET requests). If they are to be
published, put them outside of WEB-INF in a folder or may be the app
root.

Hope this helps, as I am not sure if I understood the problem
statement completely.

-cheers,
Manish

 
Chris





PostPosted: 2007-10-3 8:53:00 Top

java-programmer >> relative paths for properties files in a web app Dundonald wrote:
> I want to plug an API in to a web app. The API has a properties file
> that has properties defining the relative location of particular
> files. The questions I have are
>
> 1. where should I store such 'particular files', indeed including the
> properties file itself - should I manually load them in to the WEB-INF
> directory?
>
> and
>
> 2. how do I relatively relate to the path of the files located inside
> the web app (for example in the WEB-INF) inside the properties file.
>
> I hope that makese sense.
>
> Thanks
>

You can get at a file in the WEB-INF directory from within a JSP page by
doing this:

<%
String path = application.getRealPath("WEB-INF");
File file = new File(path, "myproperties.properties");
%>

application is a predefined variable in a JSP page, just like request
and response.

 
 
Dundonald





PostPosted: 2007-10-6 6:40:00 Top

java-programmer >> relative paths for properties files in a web app On Oct 3, 12:30 am, Manish Pandit <email***@***.com> wrote:
> On Oct 2, 1:46 pm,Dundonald<email***@***.com> wrote:
>
>
>
> > I want to plug an API in to a web app. The API has a properties file
> > that has properties defining the relative location of particular
> > files. The questions I have are
>
> > 1. where should I store such 'particular files', indeed including the
> > properties file itself - should I manually load them in to the WEB-INF
> > directory?
>
> > and
>
> > 2. how do I relatively relate to the path of the files located inside
> > the web app (for example in the WEB-INF) inside the properties file.
>
> > I hope that makese sense.
>
> > Thanks
>
> The property file can reside as an application resource in the
> classpath. Read up on Resource Bundles in Java for more information
> (including APIs like Class.getResourceAsStream()). As far as the path
> goes, the files can stay under WEB-INF if they are not be served
> directly to the browsers (via HTTP GET requests). If they are to be
> published, put them outside of WEB-INF in a folder or may be the app
> root.
>
> Hope this helps, as I am not sure if I understood the problem
> statement completely.
>
> -cheers,
> Manish

Thanks Manish.

I have created a properties resource folder and told WSAD to store
'compiled' (of course they're not compiled) version of properties in
to WEB-INF. So properties file x is in WEB-INF.

The final outstanding question is if for example inside properties
file x a line there is a line such as :

resource_name=./some_file

does that mean that the relative path ./ insinuates that some_file
should be also inside the WEB-INF directory? Does that make sense?

Thanks

 
 
Dundonald





PostPosted: 2007-10-6 6:44:00 Top

java-programmer >> relative paths for properties files in a web app On Oct 3, 1:53 am, Chris <email***@***.com> wrote:
> Dundonaldwrote:
> > I want to plug an API in to a web app. The API has a properties file
> > that has properties defining the relative location of particular
> > files. The questions I have are
>
> > 1. where should I store such 'particular files', indeed including the
> > properties file itself - should I manually load them in to the WEB-INF
> > directory?
>
> > and
>
> > 2. how do I relatively relate to the path of the files located inside
> > the web app (for example in the WEB-INF) inside the properties file.
>
> > I hope that makese sense.
>
> > Thanks
>
> You can get at a file in the WEB-INF directory from within a JSP page by
> doing this:
>
> <%
> String path = application.getRealPath("WEB-INF");
> File file = new File(path, "myproperties.properties");
> %>
>
> application is a predefined variable in a JSP page, just like request
> and response.

Thanks Chris.

 
 
Manish Pandit





PostPosted: 2007-10-6 7:28:00 Top

java-programmer >> relative paths for properties files in a web app On Oct 5, 3:40 pm, Dundonald <email***@***.com> wrote:
> On Oct 3, 12:30 am, Manish Pandit <email***@***.com> wrote:
>
>
>
>
>
> > On Oct 2, 1:46 pm,Dundonald<email***@***.com> wrote:
>
> > > I want to plug an API in to a web app. The API has a properties file
> > > that has properties defining the relative location of particular
> > > files. The questions I have are
>
> > > 1. where should I store such 'particular files', indeed including the
> > > properties file itself - should I manually load them in to the WEB-INF
> > > directory?
>
> > > and
>
> > > 2. how do I relatively relate to the path of the files located inside
> > > the web app (for example in the WEB-INF) inside the properties file.
>
> > > I hope that makese sense.
>
> > > Thanks
>
> > The property file can reside as an application resource in the
> > classpath. Read up on Resource Bundles in Java for more information
> > (including APIs like Class.getResourceAsStream()). As far as the path
> > goes, the files can stay under WEB-INF if they are not be served
> > directly to the browsers (via HTTP GET requests). If they are to be
> > published, put them outside of WEB-INF in a folder or may be the app
> > root.
>
> > Hope this helps, as I am not sure if I understood the problem
> > statement completely.
>
> > -cheers,
> > Manish
>
> Thanks Manish.
>
> I have created a properties resource folder and told WSAD to store
> 'compiled' (of course they're not compiled) version of properties in
> to WEB-INF. So properties file x is in WEB-INF.
>
> The final outstanding question is if for example inside properties
> file x a line there is a line such as :
>
> resource_name=./some_file
>
> does that mean that the relative path ./ insinuates that some_file
> should be also inside the WEB-INF directory? Does that make sense?
>
> Thanks- Hide quoted text -
>
> - Show quoted text -

I would not recommend using relative paths in properties file to look
up resources for a webapp. To give you an example, if I run Tomcat
(installed in c:\jakarta-tomcat) from within Eclipse (installed in c:
\eclipse) and print System.getProperty("user.dir"), it shows c:
\eclipse. The JSP that prints this sits in c:\workspace\myapp\. You
can clearly see all the variables in play here. Best option will be to
use absolute paths for this purpose. If you want context sensitive
paths, then use look up these resources via the classloader
(getResourceAsStream) and use /some_file instead of ./some_file. As
long as some_file is in the classpath, it'll be picked up. I believe
that is how Spring looks up it's configuration files, etc. as well.

-cheers,
Manish

 
 
Dundonald





PostPosted: 2007-10-6 16:35:00 Top

java-programmer >> relative paths for properties files in a web app On Oct 6, 12:27 am, Manish Pandit <email***@***.com> wrote:
> On Oct 5, 3:40 pm,Dundonald<email***@***.com> wrote:
>
>
>
> > On Oct 3, 12:30 am, Manish Pandit <email***@***.com> wrote:
>
> > > On Oct 2, 1:46 pm,Dundonald<email***@***.com> wrote:
>
> > > > I want to plug an API in to a web app. The API has a properties file
> > > > that has properties defining the relative location of particular
> > > > files. The questions I have are
>
> > > > 1. where should I store such 'particular files', indeed including the
> > > > properties file itself - should I manually load them in to the WEB-INF
> > > > directory?
>
> > > > and
>
> > > > 2. how do I relatively relate to the path of the files located inside
> > > > the web app (for example in the WEB-INF) inside the properties file.
>
> > > > I hope that makese sense.
>
> > > > Thanks
>
> > > The property file can reside as an application resource in the
> > > classpath. Read up on Resource Bundles in Java for more information
> > > (including APIs like Class.getResourceAsStream()). As far as the path
> > > goes, the files can stay under WEB-INF if they are not be served
> > > directly to the browsers (via HTTP GET requests). If they are to be
> > > published, put them outside of WEB-INF in a folder or may be the app
> > > root.
>
> > > Hope this helps, as I am not sure if I understood the problem
> > > statement completely.
>
> > > -cheers,
> > > Manish
>
> > Thanks Manish.
>
> > I have created a properties resource folder and told WSAD to store
> > 'compiled' (of course they're not compiled) version of properties in
> > to WEB-INF. So properties file x is in WEB-INF.
>
> > The final outstanding question is if for example inside properties
> > file x a line there is a line such as :
>
> > resource_name=./some_file
>
> > does that mean that the relative path ./ insinuates that some_file
> > should be also inside the WEB-INF directory? Does that make sense?
>
> > Thanks- Hide quoted text -
>
> > - Show quoted text -
>
> I would not recommend using relative paths in properties file to look
> up resources for a webapp. To give you an example, if I run Tomcat
> (installed in c:\jakarta-tomcat) from within Eclipse (installed in c:
> \eclipse) and print System.getProperty("user.dir"), it shows c:
> \eclipse. The JSP that prints this sits in c:\workspace\myapp\. You
> can clearly see all the variables in play here. Best option will be to
> use absolute paths for this purpose. If you want context sensitive
> paths, then use look up these resources via the classloader
> (getResourceAsStream) and use /some_file instead of ./some_file. As
> long as some_file is in the classpath, it'll be picked up. I believe
> that is how Spring looks up it's configuration files, etc. as well.

Thanks again Manish.