An API for loading and using configuration files, see the project site for more information.
Typically you would load configuration with a static method from {@link com.typesafe.config.ConfigFactory} and then use it with methods in the {@link com.typesafe.config.Config} interface. Configuration may be in the form of JSON files, Java properties, or HOCON files; you may also build your own configuration in code or from your own file formats.
An application can simply call {@link com.typesafe.config.ConfigFactory#load()} and place
its configuration in "application.conf" on the classpath.
If you use the default configuration from {@link com.typesafe.config.ConfigFactory#load()}
there's no need to pass a configuration to your libraries
and frameworks, as long as they all default to this same default, which they should.
Example application code: Java and Scala.
Showing a couple of more special-purpose features, a more complex example: Java and Scala.
A library or framework should ship a file "reference.conf" in its jar, and allow an application to pass in a
{@link com.typesafe.config.Config} to be used for the library. If no {@link com.typesafe.config.Config} is provided,
call {@link com.typesafe.config.ConfigFactory#load()}
to get the default one. Typically a library might offer two constructors, one with a Config
parameter
and one which uses {@link com.typesafe.config.ConfigFactory#load()}.
Example library code: Java and Scala.
Check out the full examples directory on GitHub.
What else to read:
.conf
files in addition to .json
and .properties
,
see the README for some short examples
and the full HOCON spec for the long version.