Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

best place to put configuration properties.

 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
" make a build file "

Did not get it. Can you please explain it in more detail ?
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
make a ant build file to do the task.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jigar Naik:
Can you please explain it in more detail


Refer this to create build file
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic