Commons CLI

转载 2013年12月04日 13:54:55

Commons CLI

The Apache Commons CLI library provides an API for parsing command line options passed to programs. It's also able to print help messages detailing the options available for a command line tool.

Commons CLI supports different types of options:

  • POSIX like options (ie. tar -zxvf foo.tar.gz)
  • GNU like long options (ie. du --human-readable --max-depth=1)
  • Java like properties (ie. java -Djava.awt.headless=true Foo)
  • Short options with value attached (ie. gcc -O2 foo.c)
  • long options with single hyphen (ie. ant -projecthelp)

A typical help message displayed by Commons CLI looks like this:

usage: ls
 -A,--almost-all          do not list implied . and ..
 -a,--all                 do not hide entries starting with .
 -B,--ignore-backups      do not list implied entried ending with ~
 -b,--escape              print octal escapes for nongraphic characters
    --block-size <SIZE>   use SIZE-byte blocks
 -c                       with -lt: sort by, and show, ctime (time of last
                          modification of file status information) with
                          -l:show ctime and sort by name otherwise: sort
                          by ctime
 -C                       list entries by columns

Check out the introduction page for a detailed presentation.

CLI 2?

Commons CLI 1.0 was formed from the merger of ideas and code from three different libraries - Werken, Avalon and Optz. In dealing with the bugs and the feature requests a freshly designed and not backwards compatible CLI 2 was created in 2004, but never finished or released.

The current plan is to continue to maintain the 1.x line. The CLI2 work may be found in the Commons Sandbox.


A full User's Guide is available as are various project reports.

The Javadoc API documents are available online:

The Subversion repository can be browsed.


The latest version is v1.2. - Download now!
The release notes are also available.

For previous releases, see the Apache Archive.


The commons mailing lists act as the main support forum. The user list is suitable for most library usage queries. The dev list is intended for the development discussion. Please remember that the lists are shared between all commons components, so prefix your email subject by [cli].


  • 2016年03月18日 09:43
  • 382KB
  • 下载


  • 2017年08月18日 15:55
  • 52KB
  • 下载




  • 2013年09月17日 09:43
  • 40KB
  • 下载


  • 2016年12月26日 23:52
  • 42KB
  • 下载

使用Apache Commons CLI开发命令行工具

本文简单介绍了如何使用Apache Commons CLI构建一个简单实用的命令行工具。


  • 2008年09月18日 19:49
  • 35KB
  • 下载


  • 2016年01月22日 17:12
  • 27KB
  • 下载

Java命令行参数类 Commons CLI使用

Commons CLI库是apache的一个子项目,比较起来,其使用方法相对规范。 Test...

使用Apache Commons CLI开发命令行工具

使用Apache Commons CLI开发命令行工具分成三步:  1)定义CLI  2)解析CLI  3)处理CLI  首先我们参考官网给出的一个例子: ant [options] [ta...
您举报文章:Commons CLI