Wednesday, April 13, 2011

Using Resource Environment Provider : A replacement for application property files.

Most J2EE Applications and for that matter, any applications uses Property File to provide the properties and attributes to it's app. While this is fine and it works as expected, however, there are instances that you would like to store these properties on your underlying server and manage it from there. Example, in my current company where I work for, (and I believe this is also on majority of MNC's), if you have an application that comes together with a property file and you need to change the property file, Operations will normally require you to do the changes on dev copy and proceed it for re-deployment. Now, in-cases where processes are in-place for you to follow, this needs to go QA regression etc. Depending on schedule, this may take more than a day to implement.

To reduce this, you may use Resource Environment Provider instead of property files to store your properties, and then do a JNDI call to your app server to do get the values. These are possible for Websphere Application Server, Tomcat, etc. You just need to find how to do it in your application server.

The complete tutorial is in this link :

What you require :
1. A class that implements ObjectFactory
2. A class that will be used to call get and set values.

1. Create a class library that implements an ObjectFactory. Here's the source code of what I did.

2. Now create a AppConfig class that is called by the factory.

3. Go to your Websphere Application Server and follow the steps as shown below :

4. Create a new provider.

5.Click on your provider.

6. Click on Referenceables and click on New. Add the Factory Class (AppConfigFactory) and the Class (AppConfig) that we've just created.

7. Click on Apply and Ok. Then go to Resource Environment Entries and create a JNDI.

8. Choose on your referenceable the AppConfigFactory that we just created. After adding, click on the Custom Properties.

9. Add the properties you need, and click apply and ok.

10. Add a JSP file on your application such as the code below :

11. Run your application. You should see your properties viewed. Try changing the properties on the custom properties and restart your application. Once run, you will see the latest changes.

Additional note. If a property in Websphere Application Server has a word password on it, it is automaticaly XORed. I guess this is the default mechanism of Websphere Application Server, to provide atleast a minimum security.



  1. Hello, i tried this and it works fine. But when i change the custom properties while my app is running then new properties are not passed to the ObjectFactory (I removed the if(config == null)). Any idea why? I would like to hot-change the properties.
    Best regards, Steffen

  2. Nobody said you could do it on the fly. However, restarting the app is still much faster than re-deploying.

  3. Any idea if this can be achieved in JBoss7 too?

  4. They are the general population to whom you can clarify your ideas, your thoughts and they will give you bona fide input. At some point certain things appears to be anything but difficult to do yet in all actuality it is troublesome so they will control you and fix your things in all actuality if conceivable. convert website to app