juneau-config
Maven Dependency

<dependency> <groupId>org.apache.juneau</groupId> <artifactId>juneau-config</artifactId> <version>7.1.0</version> </dependency>

Java Library

juneau-config-7.1.0.jar

OSGi Module

org.apache.juneau.config_7.1.0.jar

The juneau-config module defines an API allows you to interact with INI files using POJOs.
It builds upon the marshalling and SVL APIs to provide sophisticated dynamic configuration files.

#-------------------------- # My section #-------------------------- [MySection] # An integer anInt = 1 # A boolean aBoolean = true # An int array anIntArray = [1,2,3] # A POJO that can be converted from a String aURL = http://foo # A POJO that can be converted from JSON aBean = {foo:'bar',baz:123} # A system property locale = $S{java.locale, en_US} # An environment variable path = $E{PATH, unknown} # A manifest file entry mainClass = $MF{Main-Class} # Another value in this config file sameAsAnInt = $C{MySection/anInt} # A command-line argument in the form "myarg=foo" myArg = $ARG{myarg} # The first command-line argument firstArg = $ARG{0} # Look for system property, or env var if that doesn't exist, or command-line arg if that doesn't exist. nested = $S{mySystemProperty,$E{MY_ENV_VAR,$ARG{0}}} # A POJO with embedded variables aBean2 = {foo:'$ARG{0}',baz:$C{MySection/anInt}}

You're probably wondering "why INI files?"
The beauty of these INI files is that they're easy to read and modify, yet sophisticated enough to allow you to store arbitrary-complex data structures and retrieve them as simple values or complex POJOs:

// Load our config file Config c = Config.create().name("MyIniFile.cfg").build(); int anInt = c.getInt("MySection/anInt"); boolean aBoolean = c.getBoolean("MySection/aBoolean"); int[] anIntArray = c.getObject("MySection/anIntArray", int[].class); URL aURL = c.getObject("MySection/aURL", URL.class); MyBean aBean = c.getObject("MySection/aBean", MyBean.class); Locale locale = c.getObject("MySection/locale", Locale.class); String path = c.getString("MySection/path"); String mainClass = c.getString("MySection/mainClass"); int sameAsAnInt = c.getInt("MySection/sameAsAnInt"); String myArg = c.getString("MySection/myArg"); String firstArg = c.getString("MySection/firstArg");

One of the more powerful aspects of the REST servlets is that you can pull values directly from config files by using the "$C" variable in annotations.
For example, the HTML stylesheet for your REST servlet can be defined in a config file like so:

@RestResource( path="/myResource", config="$S{my.config.file}", // Path to config file (here pulled from a system property) stylesheet="$C{MyResourceSettings/myStylesheet}" // Stylesheet location pulled from config file. ) public class MyResource extends RestServlet {

Other features: