aspose file tools*
The moose likes Servlets and the fly likes Property files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Property files" Watch "Property files" New topic
Author

Property files

Manhar Puri
Ranch Hand

Joined: Aug 23, 2005
Posts: 41
My question is more related to Web Applications. I want to store some properties in a property file. To read this file I need to provide the path to the file holding the properties.

My question is:

1) what are options in order to provide this path. I can myself think of two ways
a) Hard code the path in my class
b) Give the path as a system property
The second option has the disadvantage that if I provide my app as a war it cannot be deployed as is. I do not want to use first option for obvious reasons.

2) My second question I want to be able to read the properties and load them at startup of the application. Where should I put my code to do this? Also in case I want to read these properties per user session where should I put my code to read the properties.

Thanks,

Manhar.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

http://wiki.apache.org/tomcat/HowTo#head-45c3314139cb900ddd43dde2ff671532e6e844bc

This How-to entry should be just what you're looking for.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bk Jacky
Ranch Hand

Joined: Jun 11, 2005
Posts: 74
hi
just use this API

java.io.tmpdir
this system property point to dir that does not exit.It store ur property file path in system temp directory.So, there is no need to hard code it just make instance and access the file path.

just look at this API

Bhupinder
SCJP1.4
Preparing SCWCD


SCJP1.4<br />SCWCD1.5<br />"Nothing is impossible"
Jaime M. Tovar
Ranch Hand

Joined: Mar 28, 2005
Posts: 133
Look for the getResourceAsStream method, it will let you place properties files in the same packages as your classes are. It will help you also with the war stuff because you will deploy your properties file in the same archive as your other java classes.


She will remember your heart when men are fairy tales in books written by rabbits.<br /> As long as there is duct tape... there is also hope.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Property files