wood burning stoves 2.0*
The moose likes Servlets and the fly likes best place to put configuration properties. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "best place to put configuration properties." Watch "best place to put configuration properties." New topic
Author

best place to put configuration properties.

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
where should i keep connection properties like hostName, and other properties for database conneciton, which i dont want to hard code(conneciton name & connection class). ???

Which is the best place for tham... so that in future if any modification requires than we can edit those properties without touching other code.


Jigar Naik


Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Well if you have a JNDI context to go with you can use that to store runtime values.

You can also go with a properties files (just a flat file with some name value pairs) and I would recommend that you make them available outside your .WAR file.

You can choose init parameters or context parameters also


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I would have used a application.properties file with the properties in the form of key value pair and put that in the /WEB-INF/classes folder .In the application load that property file in the property object and make use of the values.


Rahul Bhattacharjee
LinkedIn - Blog
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
allright...

I've set those parameters in .properties file but its in the war file.

How can i make it available outside the war file ? because there are some parameters which will get changed at regular interval.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I guess you are using war format for distributing/deploying.each time you change the property file , you have to replace the old property file and then make and new war and deploy it again.
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
yes, that is what my TL dont want to do.

Is there any other way i can put .properties file out side the war file and access it. ??
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by Jigar Naik:
yes, that is what my TL dont want to do.

Is there any other way i can put .properties file out side the war file and access it. ??


TL - team lead. (always use expanded version of your vocabulary)

Two things you can do.

1> instead of making the way again and again , put the property file in the exploded war , which is there inside the server.and restart the server each time you change the property file.

2> make a build file that would make your job easy .replace property , make war , deploy ,restart server.
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
" make a build file "

Did not get it. Can you please explain it in more detail ?
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
make a ant build file to do the task.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Originally posted by Jigar Naik:
Can you please explain it in more detail


Refer this to create build file


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: best place to put configuration properties.
 
Similar Threads
JSP/Java Bean problem
java.lang.NullPointerException in JDBC connection
JDBC connection closing problem in Servlets
oracle conneciton from connection object returned form connection pool
A problem in Connection pool design