File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes Best Practices - Properties files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Best Practices - Properties files" Watch "Best Practices - Properties files" New topic

Best Practices - Properties files

Ashish Gauswami

Joined: Aug 20, 2008
Posts: 22
What is the best practice for maintaining different versions of properties files like for prod, test and dev and generate war/ear out of it selecting correct version of property file using Ant?

What I have done is I have kept all three version of properties file together with .prod and .test suffix for Production and Test, and for Development just .properties. In my Ant I have written three different targets and I am coping and renaming appropriate property file.

I use RAD7 and Websphere.

SCWCD - Preparing, SCJP - 86%
Martijn Verburg

Joined: Jun 24, 2003
Posts: 3275

There are many ways to solve this problem, your method is a reasonable one. Another approach is to pass in an environment variable via the command line e.g. ant -Denv=dev and then use that to pick out the correct properties file ${env}.properties .

Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

Actually, I prefer not to make different builds for test/dev/prod. The problem with doing so is that if the production app goes down, you may have trouble keeping track of the different versions, and in some cases, the program code itself may even be different.

I get around this by creating a universal deployable and injecting the configuration information in on a per-server basis - typically via JNDI.

A side benefit of this is that if I need to do before and after comparisons, I can usually run 2 copies of the app on a single test machine just by deploying them with different contexts and configurations.

An IDE is no substitute for an Intelligent Developer.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

Tim Holloway wrote:Actually, I prefer not to make different builds for test/dev/prod.

Me too. I use different sets of property files so I just have to change the classpath of the app for the environment. (And of course other settings are in JNDI.)

I generate my property files since we have many environments. So I really only maintain one set of property files and another file with the differences.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Best Practices - Properties files
It's not a secret anymore!