Click here to Skip to main content
15,879,535 members
Articles / Programming Languages / Java / Java SE / J2EE

Applications Properties in Java

Rate me:
Please Sign up or sign in to vote.
2.00/5 (1 vote)
4 Jun 2009CPOL2 min read 21.1K   7   1
Stratagies for managing application properties in Java

Introduction

This article covers some of the techniques that can be used to store and retreive application configuration data (Aka properties) in a Java application. It currently focuses on software that is deployed to an application server such as websphere.

This artical is not about the broarder configuration management topic also it won't tell you exactly to make use of the configuration data in your application. but it is related.

Background

Most non trivial java applications need some mechanism to deal with environment related application properties. This article covers some techniques that can be used for storing and retreiving applicition configuration data*. It not and article about configuration management and it only touches on the details of how the applications actually use the properties. It will give an overview of some of the options avaliable. This focuses on an application server environment

Definition

Configuration data is mostly used as a list of key value pairs.

The approaches

  • No Configuration
  • JVM properties
  • Flat File
    • Class path properties file
    • Directly referenced properties file
    • Ini files
  • Resource environment provider (Within an application server)
  • Database properties
  • Environmental variables

No Configuration (Hard coding)

This is when the application data is kept directly within the application and any changes required for the application code to be changed and the application to be recompiled.

JVM Properties

This is when you keep all your configuration data within the jvm. These values are usually accessed using the System.getProperty method

{Code}

System.getProperty("props.myproperty");

{/Code]

Environmental variables

This is when the Data is put at the application / environment it can be globally for the operating sytem or with the id

Flat file (Aka properties file)

When a file is used to store the configuration data. The file can be within the application or outside of the application. There are a number of mechanisms to find these and two common approaches are to look them up using a System property to specify their location the other is to look for a class path relative file.

Database properties

When a table is used within a database to keep the application configuration data usually there will be a table that has a column relating to the property / key and a coresponging the the value e.g.

Key / PropertyValue
property.key1key1 value
property.key2key2 value

Resource Environment provider

In Websphere Appllication server 6.1 it is possible to store the properties within a resource environment provider. This enables the properties to be retreived as an object via a JNDI lookup the actual object retreived depends on the how the lookup is implemented but its a mechanism for storing properties.

http://www.ibm.com/developerworks/websphere/library/techarticles/0611_totapally/0611_totapally.html

References

Resource Environment Provider -> http://www.ibm.com/developerworks/websphere/library/techarticles/0611_totapally/0611_totapally.html

Commons Configuration -> http://commons.apache.org/configuration/

Database props -> http://www.springbyexample.org/twiki/bin/view/Example/SpringModulesWithCommonsConfiguration

History

Danielp 2009-04-01 - Initial release still work todo

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Australia Australia
First Started developing professionaly in 2004. I have mostly worked across the IBM products with a dash of open source components added in. My IBM Product Experience includes Websphere, DB2, IBM Content Manager EE, RAD. On the Open Source side some of the noteworthy components are Spring, Tapestry, Junit plus a bunch of utility apis.

Comments and Discussions

 
GeneralMy vote of 2 Pin
Colin Eberhardt4-Jun-09 21:24
Colin Eberhardt4-Jun-09 21:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.