Moved!

This version at SourceForge is no longer maintained! As of version 2.0 it is now available at https://github.com/tombensve/OptionsManager. It has also changed package. For more information se docs at the new place.

Short Description

Manages application/tool options. Options are mapped to Java Bean properties using annotations. Help texts can be specified for options also using annotations and a complete help text can be generated by the options manager. Options can be loaded from command line arg String[] array, an XML file, or a java properties file.

Please note that even if this tool can load XML data into a JavaBean it is not an XML to Java tool! Even if it can be used as such it is very limited for that use. It is only indented for mapping user options/configuration from some source into a structure of JavaBeans for which one such source happens to be XML. For an XML - JavaBean mapper I recommend either JAXB (https://jaxb.dev.java.net/) or Simple (http://simple.sf.net/) or XOB (http://xob.sf.net/) which are all indended for such use.

Simple example

The following is a simple options model:

  @OptionsModel(name="")
  public class BreadOptions {
      
      @Option(description="Specifies the oven temperature",
              required="true")
      private float ovenTemp;
                  
      @Option(name="bakeTime",
              description="The amunt of time to bake.")
      private int bakeTimeMinutes = 120;
       
      @Option(description="Displays help.", flag=true)
      private boolean help = false;
      
      ...
      
      // Setters & Getters
       
      ...
  }

If you dont like annotations with a long list of attributes the following example is identical in functionality:

  @OptionsModel(name="")
  public class BreadOptions {
      
      @Option
      @Description("Specifies the oven temperature")
      @Required
      private float ovenTemp;
      
      @Option
      @Name("bakeTime")
      @Description("The amunt of time to bake.")
      @Optional
      private int bakeTimeMinutes = 120;
      
      @Option
      @Description("Displays help.")
      @Flag
      private boolean help = false;
      
      ...
      
      // Setters & Getters
       
      ...
  }

This model would be loaded from a command line tool with:

  public void main(String[] args) {
    CommandLineOptionsManager<BreadOptions> clom = 
      new CommandLineOptionsManager(BreadOptions.class);
    
    // Make our options "--" prefixed.
    BreadOptions breadOptions = clom.loadOptions("--", args);
    
    if (breadOptions.isHelp()) {
      clom.printHelpText("--","", System.out);
    }
    else {
      ...
    }
  }

This allows the user to pass arguments like "--ovenTemp 85 --bakeTime 120".

Please note the @OptionsModel(name="") on the BreadOptions class. If we didn't specify that annotation the name would be "breadOptions" and the arguments would be "--breadOptions-ovenTemp 85 --breadOptions-bakeTime 120 ...". In the case of command line argument options you dont usually want to use the name of the options model as part of the argument specification.

See the User Guide for more more detailed information.