Download the javaconfig-1.3.zip file; you might also want to get the sources as they contain useful examples.
In the zipfile you downloaded there's a file "javaconfig-1.3.jar". This contains everything you need in an application. The other files in the archive consist of documentation, examples and files to build Java Config yourself.
Create your own config class that for the properties you need. Extensive examples can be found in the source-zip file, here's an example:
public class SimpleConfig extends Config { /** * Name of the file we are looking for to read the configuration. */ public static final String RESOURCE_NAME = "simpleconfig.properties"; /** * Creates a new SimpleConfig object. */ public SimpleConfig(String resourceName) { super(resourceName); } public boolean isThisANiceClass() { return getBoolean("doIlikeThisClass"); } public String getWelcomeText() { return getString("property.welcome"); } public URL getNiceWebsite() { return getURL("property.nicewebsite"); } public int getNumberOfDays() { return getInt("property.numberofdays"); } }
The SimpleConfig can be filled with a property-file such as the following one. The format of such as property file is that of a standard Java Properties file.
property.welcome=Hi, this is a String! property.nicewebsite=http://www.chess.nl property.numberofdays=90 #this is a comment line. doIlikeThisClass yes property.notused=This property is not used at all.
Now, to use the configuration somewhere in your application, make sure that the property-file above is somewhere in your classpath, reachable under "simpleconfig.properties". A major functionality of the Java Config class is to verify the contents of a given property file in a simple method call. The following call shows some features:
config = new SimpleConfig(SimpleConfig.RESOURCE_NAME); ConfigValidationResult configResult = config.validateConfiguration(); if (configResult.thereAreErrors()) { System.out.println("Errors in configuration"); for (Iterator iter = configResult.getErrors().iterator(); iter.hasNext();) { System.out.println(" > " + iter.next()); } System.exit(1); } if (configResult.thereAreUnusedProperties()) { System.out.println("Unused properties"); for (Iterator iter = configResult.getUnusedProperties().iterator(); iter.hasNext();) { System.out.println(" > " + iter.next()); } }