Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

relative paths for properties files in a web app

Thread view: 
Dundonald - 02 Oct 2007 21:46 GMT
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 - 03 Oct 2007 00:30 GMT
> 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
[quoted text clipped - 12 lines]
>
> 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
Dundonald - 05 Oct 2007 23:40 GMT
> > 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
[quoted text clipped - 26 lines]
> -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
Manish Pandit - 06 Oct 2007 00:27 GMT
> > > 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
[quoted text clipped - 44 lines]
>
> - 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 - 06 Oct 2007 09:34 GMT
> > > > 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
[quoted text clipped - 56 lines]
> 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.
Chris - 03 Oct 2007 01:53 GMT
> 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
[quoted text clipped - 12 lines]
>
> 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 - 05 Oct 2007 23:43 GMT
> Dundonaldwrote:
> > I want to plug an API in to a web app. The API has a properties file
[quoted text clipped - 24 lines]
> application is a predefined variable in a JSP page, just like request
> and response.

Thanks Chris.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.