Chapter 4. How It Works

Table of Contents

Creating a JSAP to do the parsing.
Defining your program's parameters.
Registering your parameters with JSAP.
Parsing the command line.
Using the JSAPResult

Everything you do with JSAP leads to the same goal: a JSAPResult object that contains objects created from the parsed command line. Getting to this point requires the following steps:

Creating a JSAP to do the parsing.

This is generally accomplished through JSAP's no-argument constructor. Depending upon the complexity of your program, however, you may want to instantiate a custom JSAP subclass that also takes care of steps 2 and 3 (described below) during the construction process. This approach results in a much "cleaner" main class. Another helpful class is SimpleJSAP, which provides on-the-fly declaration of program name, description, and parameters.

Tip

If you have a complicated command line configuration, create your own subclass of JSAP and override its constructor so it can initialize itself. This keeps your main class uncluttered.

As of version 2.0, there is an experimental mechanism to load a fully configured JSAP from a simple XML file. See this section for details.