Skip to content
Simple configuration for the JVM.
Java Shell
Find file
Latest commit 23db74a Mar 24, 2012 @criccomini adding scala readme
Failed to load latest commit information.
fig-cli rename to autoloader Mar 24, 2012
fig-core cleaning up scala test pom stuff Mar 24, 2012
fig-example remove warnings. update readme. remove parent pom relative path. Mar 23, 2012
fig-json
fig-scala_2.9.1 cleaning up scala test pom stuff Mar 25, 2012
fig-zookeeper config now implements map. Mar 23, 2012
.gitignore renaming configuration to config because i'm a bit ocd Mar 23, 2012
CHANGELOG.md adding license, contributors, and change log Mar 24, 2012
CONTRIBUTORS.md adding license, contributors, and change log Mar 24, 2012
LICENSE
README.md adding scala readme Mar 24, 2012
pom.xml

README.md

Fig

Fig is a simple configuartion library for the JVM.

Why?

  • No static methods
  • Pluggable
  • No types
  • Stupid simple
  • Immutability
  • Scala support

Using Fig

Fig is really easy to use. I promise.

Let's use Fig with a Java property file.

hello=world

Now, in Java, you can get your properties.

Config config = new AutoLoader().getConfig(new URI("file:///tmp/config.properties"));
System.out.println("hello " + config.get("hello"));

Scala Implicits

Fig also has an implicit to make life easier for Scala users.

import fig.scala.conversions.ConfigConversions._
val config: Config = new URI("file:///tmp/config.properties")
println("hello " + config.get("hello"));

Command Line Execution

Fig also provides an easy way to execute programs from the CLI using config (instead of CLI arguments).

Let's create another Java property file.

main-class=fig.example.MyConfigPrinter
foo=bar

The main-class allows us to execute the MyConfigPrinter.

./bin/run-config.sh --config-path=file:///tmp/config.properties

It really is that simple!

Example Project

Fig has an example project called "fig-example", which demonstrates how to use Fig with the run-config.sh script.

Follow these instructions to try things out.

git clone git://github.com/criccomini/fig.git
cd fig
mvn clean package
cd fig-example/target
unzip fig-example-bin.zip
cd fig-example
./bin/run-config.sh --config-path=file://`pwd`/config/example.properties

This will execute a little Java class that prints the configuration in example.properties.

Extensibility

Fig comes with a lot of FileSystems and ConfigDeserializers out of the box, but you can always extend Fig to use your own config system by using the following Java properties.

-Dfig.fs=http:fig.fs.HttpFileSystem,hdfs:fig.fs.HadoopFileSystem
-Dfig.deserializers=yaml:fig.serializers.YamlDeserializer

Now, AutoLoader will support URIs with an HTTP or HDFS scheme (http://.. or hdfs://..) and YAML config files (*.yaml).

new AutoLoader().getConfig(new URI("http://localhost/my-config.yaml"));

How great is that?

Rules of the Game

Since configuration is often a core and pervasive part of an API, Fig makes the following guarantees.

  1. Fig uses semantic versioning (http://semver.org/), and will never make backwards incompatible changes without bumping the major version (*.0.0).
  2. Fig's core library (fig-core) will never have any dependencies.
Something went wrong with that request. Please try again.