Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best way to handle properties

 
Pete Hitchman
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a large amount of Java code that contains a number of property files, that specify such things a JDBC connection strings. These property files are held in side of a JAR file. This is fine until things like server/database names start to change and we have to update the right property file in the jar file.
What is the best way to handle such things? I have thought about using the "-D" option with the Java command and then accessing the setting via the System's object properties. I would prefer if at least some of the settings could be changed without having to mess with updating a jar file.

Thanks

Pete
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pete Hitchman:
Hi,
I have a large amount of Java code that contains a number of property files, that specify such things a JDBC connection strings. These property files are held in side of a JAR file. This is fine until things like server/database names start to change and we have to update the right property file in the jar file.
What is the best way to handle such things? I have thought about using the "-D" option with the Java command and then accessing the setting via the System's object properties. I would prefer if at least some of the settings could be changed without having to mess with updating a jar file.

Thanks

Pete


-Have PM'd as well-

Hi Pete,

There are many 'solutions' to this problem and I'm sure others will post theirs, one that I use often is to have the properties files stored under the WEB-INF directory structure (I assume you're deploying a web app here?) or other secure folder but _not_ in a JAR file. I usually then use a singleton pattern that reads in and caches the properties.

Then depending on user requirements I'll implement a refresh of the properties every x seconds, or check to see if a property has changed every time a request comes in or ... etc. In the apps that I've been asked to build/deploy, production support staff and/or clients typically want to be able to alter certain properties on the fly, scary I know!

Hope that helps!

Karianna
 
Pete Hitchman
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In this case a web application is not involved. I have considered taking the property files out of the jar file. This might be the easiest solution.

Regards

Pete
 
Fletcher Estes
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally the approach I take is to have everything un-compiled, un-jarred and un-everythinged in one place, where all development takes place (including updates to properties files). Any time a change is made, I run an Ant script which will re-compile, re-pack etc. everything the way God intended, so I don't need to worry about finding the right Jar, and correctly updating a single file therein. This makes sense during the development phase of an app.

The purpose of packaging things in JARs is to make "complete" code or packages available for easy transmission and use for the end user - they are not designed to allow flexibility of updates. So, if you need to make frequent changes to a property (independent of the application), this property, as you have concluded, should definitely not be hidden in a JAR file.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic