7.1. Obtaining Commons CLI
Problem
You need to use Commons CLI (Command-Line Interface) to parse an application’s command-line arguments.
Solution
Download Commons CLI 1.0. Following the steps outlined in
Recipt 1.1, download “Commons
CLI 1.0” instead of Commons Lang. The Commons CLI
archive—cli-1.0.zip—contains a file
named commons-cli-1.0.jar; place this JAR file
in your classpath, and you are ready to use Commons CLI in your
application.
Discussion
Commons CLI provides a standard mechanism for parsing command-line
arguments. Contained in the org.apache.commons.cli
package, CLI provides a set of classes that can parse command-line
arguments containing optional arguments, arguments with parameters,
and short and long arguments. As shown in this chapter, CLI also
provides a mechanism for printing out usage information.
See Also
For more information about Commons CLI, see the Commons CLI project page (http://jakarta.apache.org/commons/cli).
For C developers, see the getopt and argp in the GNU C Library. For more information, see the section “Parsing Program Arguments” in the GNU C Library manual (http://www.gnu.org/software/libc/manual/html_node/index.html).
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access