views:

46

answers:

2

Does anybody have a good solution for managing .properties files in a web application? Currently I have to pull apart my .war file before deploying, change the entries in my .properties file, and then redeploy to change settings.

Alternatively I can ssh into the server, change the .properties file in the deploy directory and restart the application.

A coworker has a rather elegant solution of using the GUI for setting JNDI properties in your Tomcat/Glassfish instance and reading those instead of a .properties file. The problem here is that when handing off the application to our operations teams they need to know which properties to add to JNDI.

Has anybody found a great way to deal with this issue?

+1  A: 

if you can store the properties in xml format(which I believe jdk supports) then there are bunch of open source libs that can generate the crud ui for that....if not the closest i found is PropertySet @ link text

Pangea
+3  A: 

One simple option is to store the properties file external to the WAR file / webapp, so that 1) they are not changed on each deployment and 2) do not need to be edited. You would simply need to adjust the logic in your webapp having to do with where the files are found.

Another option, only slightly less simple, is to use filtering during the build process so that the WAR file is build to contain properties file that are customized to the target environment. Both Ant and Maven support a very easy mechanism for using tokens and filter files to filter certain resources.

matt b
++ to matt b@Benju - Good to put the properties files someplace generic and if you want to abstract the location of the properties file, abstract the path through a JNDI variable or a JVM variable. This way you can dynamically figure out where the properties file is and load only the values needed for that environment. Another option is to store the properties files for all environments in your WAR with _envName in the name of file (like myProperites_dev.properties, etc.) Now you just use the JNDI or JVM method to look up the env and figure out which property file to read from at run time.
Chris Aldrich