Two Laptop Bag*
The moose likes Servlets and the fly likes Where is a good place to put application-wide properties files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Where is a good place to put application-wide properties files" Watch "Where is a good place to put application-wide properties files" New topic
Author

Where is a good place to put application-wide properties files

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

This might be more of an ANT or deployment question, but I'll start here. If it belongs elsewhere, we can move the thread.


I've been putting assorted .properties files in the WEB-INF/classes directory, and it works fine.

But, I've checked in these files into SVN, and when a user does a checkout, they get the "standard" versions. And that may not be where we want to get them, or where they should be.

The problem is that I put lots of stuff in the properties, such as host name for SMTP servers, the Host and URL for JDBC, usernames for the "from" field of outgoing email notices, etc. When I'm developing, I usually want to use a non-production set of values. And I can see that the marketing folks might want a copy on their laptops to show in demos. Clearly "production" wants real values.

What's a clean way to handle this?

Thanks
pat
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61082
    
  66

I keep mine in a folder in the source tree and copy them to classes folder as part of the ant build. That way, they are not an svn issue.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Bear Bibeault wrote:I keep mine in a folder in the source tree and copy them to classes folder as part of the ant build.

But aren't all the files and folders in your source tree checked into SVN?

I was thinking of some hack where I look for a magic enviroment variable, something like PAT_CONFIG_HOME, and if its there, read from there, else let
the usual WAR/JAR rules hold. This feels like a hack.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61082
    
  66

So you don't want the deployed version to be in svn?

My scenario allows local developers to keep their private versions in the classes folder without svn issues. The "official" version is what is in svn, and is copied into the war file for deployment.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Bear Bibeault wrote:So you don't want the deployed version to be in svn?

My scenario allows local developers to keep their private versions in the classes folder without svn issues. The "official" version is what is in svn, and is copied into the war file for deployment.


Of course, I want to have everything in svn, so I can install an OS, and svn, and pull everything out of the repository. And then a miracle occurs.

Perhaps I don't understand your approach. If the ant script is in svn, like mine is using netbeans, then the usual clean and build will get the usual "production" results.

Perhaps if you explained a bit more?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

There are a million ways to handle this.

I usually end up with a hostname-based solution and/or a system property name-based one, either home-brewed or through a Spring-based PropertyPlaceholderConfigurator extension. We've always checked in developer-/host-specific files, although sometimes we've ended up with "local.properties"-like files that aren't under version control. I try to avoid that when possible.

YMMV.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61082
    
  66

There's the "official" properties files in the source tree. When a developer is running a local copy, he copies them to his classes folder and makes any necessary local changes. These are not part of the source tree and so there is no danger of them getting checked in with local changes.

During a build, the "official" versions become part of the war file for deployment.
 
wood burning stoves
 
subject: Where is a good place to put application-wide properties files