Newsflash

Now you can Submit Articles and News to GratisJSP.

 

 

Main Menu

Home
About
News
Search

Login Form






Lost Password?
No account yet? Register
powered_by.png, 1 kB
Home arrow Articles arrow Technical Articles arrow Apache Commons Configuration
Apache Commons Configuration Print
Written by Samuel   
fredag, 21 september 2007
Article Index
Apache Commons Configuration
Page 2
Page 3
As a Java programmer you know that you often need to make a progam configurable. One common way to configure a Java application is to use the java.util.Properties. The usage of Properties is rather simple but has its disadvantages. Dynamic update in the program when changing the configuration file is a commonly needed function that Properties is lacking. The Apache Commons Configuration (http://commons.apache.org/configuration/) project includes more functions and features than Java Properties, including automatic reloading. In this article we will look at a small Java program that uses the Commons Configuration. Changes in the configuration file will automatically be reloaded to the program.

Commons Configuration depends on:

  • Commons Lang
  • Commons Logging
  • Commons Collections 

Download the components above from Apache.org and setup your development environment so the JAR files are found in the CLASSPATH.

Example #1

Let’s start with a very simple application.

public final class Configurator {
 private FileConfiguration config;
 public Configurator() {
   config = new XMLConfiguration("app.xml");
   System.out.println("title: "+config.getString(“title”));
 }
 public static void main(String[] args) {
  Configurator c = null;
  c = new Configurator();
 }
}

The configuration file app.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<myApplication>
    <title>My application</title>
</myApplication>


If you can get this application up and running plus reading the configuration file your environmnet is working fine.



Last Updated ( lördag, 23 februari 2008 )
 
< Prev   Next >
© 2009 GratisJSP.org - Articles
Joomla! is Free Software released under the GNU/GPL License.