A Funny Java Flavoured Look at the World

Friday, June 16, 2006

Extending Properties Files

I developer at work came up with a novel idea regarding a properties file we use in our software. This properties file has to be changed for some properties to be set. This means letting the user change the file, this means that sometimes they can get set with dodgy values.


One of the other advantages is that sometimes when we want to upgrade a user sometimes it easier to reinstall a new version and then copy the their settings like properties files and a few other config files back. There is also times when we have to add things to the properties file when they upgrade etc.


Basically what I am trying to say is that it can be a source of syntax bugs by misspellings, incorrect values etc.


He came up with the notion of have a properties file and then have a custom properties file. Any values in the custom properties file overwrites the value in the properties file. This custom properties file is exactly the same as the properties file except all the values are commented out.


When a customer/user wants to change a value they can uncomment the value and change it. This allows the customers to see what values are in the (default) properties file and always have a value there if they need to go back to the value. It also will mean that we can also easily see the values they have changed, which should help to speed up finding any problems in the properties file. Lastly this should make it easier to upgrade users because we can just replace their properties file and leave their custom properties alone.


It also works well in a programming sense because it is like extending the properties file and overwriting the values they want overwritten and leaving the other values as they were. I also explained to the developer that it fits one of my favourite programming practices or something else.


“closed for change but open for extension”

3 Comments:

  • We've been doing something similar for years, but we've taken it a little further than you by using replacement markers. Here is the general syntax:

    #base.properties:

    db.url : jdbc:jtds://${db.host}:${db.port}/${db.name}
    db.port : 1433
    db.host : localhost
    filters : auth;cache

    #custom.properties:

    db.host : dbserver1
    db.name : petstore
    filters : ssl;${filters}

    By Anonymous Michael Slattery, at Fri Jun 23, 11:16:00 am 2006  

  • Also agreed. Generally a good idea. Not really novel, though. As it says in Ecclesiastes, there's nothing new under the sun. But meanwhile, thanks for publicly highlighting a nice idea.

    By Anonymous Anonymous, at Fri Jun 23, 04:06:00 pm 2006  

  • cell phonesThis phenomenom is typified by mobile phonethe rise ofbusiness. Incredible range of products available with China Wholesale “Low Price and High Quality” not only reaches directly to their target clients worldwide but also ensures that cheap cell phones wholesale from China means margins you cannot find elsewhere and China Wholesale will skyroket your profits.

    By Blogger crazyloko, at Fri Nov 20, 03:23:00 am 2009  

Post a Comment

Links to this post:

Create a Link

<< Home