How to Use Apache Commons Configuration

1) Create the sample.properties file:

message=Hello World!

2) Create the CommonsSample.java file:

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.PropertiesConfiguration;

import static java.lang.System.out;

public final class CommonsSample {

  public static void main(final String[] args) throws Exception {
    final Configuration config = new PropertiesConfiguration("sample.properties");

    out.println(config.getString("message"));
  }

}

3) Compile the CommonsSample.java file.

4) Launch the CommonsSample class.

2 thoughts on “How to Use Apache Commons Configuration

  1. At compile time I received the message:

    cannot access
    org.apache.commons.lang.exception.NestableException
    file
    org\apache\commons\lang\exception\NestableException.class
    not found.

    I´ve commons-configuration-1.2.jar in my class path
    but inside this file there no one filed called
    NestableException.class

    How could I solve this error ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s