Skip to content
This repository was archived by the owner on Dec 8, 2023. It is now read-only.
Tiago Simão edited this page Sep 24, 2015 · 3 revisions

How to use

In a library

Include this dependency

<dependency>
  <groupId>org.irenical.jindy</groupId>
  <artifactId>jindy-api</artifactId>
  <version>1.0</version>
</dependency>

From anywhere in your code, call

Config config = ConfigFactory.getConfig();

With the returned Config object you can do the following

Fetch a value

config.getString("my.property");

Fetch a value or a default if none is defined

config.getString("my.property","my default string");

Force error handling if a value is not defined

try{
    config.getMandatoryString("my.property");
} catch(ConfigNotFoundException noConfig){
    ...
}

Caution: Do not include an actual implementation of a binding in your library, as that will force all projects downstream to contain it.

In a final application (a war, an executable jar, a test suite, etc...)

Same as in a library but you have to include an actual implementation (a binding). No library in your upstream should include a Jindy binding, as it would force that upon your application. Multiple bindings are not allowed, you should get a runtime error if more than one (or none) are detected.

Creating your own binding

jindy-api only provides the API, not any implementation of actual configuration retrieval. For the Config API to work in runtime, you must add a valid binding to your final application. You can build one from scratch, or extend one of the following:

Using Apache Commons Configuration

Using Netflix's Archaius

Clone this wiki locally