picocli is different from other Java CLI libraries:
- It is designed to be included in source form. This lets users run picocli-based applications without requiring picocli as an external dependency.
- Generates polished and easily tailored usage help, using ANSI colors when the underlying platform supports it.
- Autocompletion for your Java command line applications on supported platforms
Example usage help message:

Quick overview:
- Effortless command line parsing - just annotate fields
- Strongly typed everything - command line options as well as positional parameters
- full support for both GNU style and POSIX clustered short options (so it handles
<command> -xvfInputFileas well as<command> -x -v -f InputFile) - An arity model that allows a minimum, maximum and variable number of parameters, e.g,
"1..*","3..5" - Subcommands
- Works with Java 5 and higher
- Well-structured user manual
Usage help is the face of your application, so be creative and have fun!

Update:
Picocli is also actively maintained. Since the original post, many new features were added, for example:
- programmatic API as well as annotations API
- Dependency Injection container integration
- JLine integration: delegate to AutoComplete for your command’s Completer implementation
- interface methods can be annotated with
@Optionor@Parameters(picocli creates a synthetic implementation that returns the matched options) - class methods can be annotated with
@Optionor@Parameters(so you can validate options and positional parameters) - support for
@Commandmethods for extra compact code - internationalization with resource bundles
Disclaimer: I am the author.
Answer from Remko Popma on Stack Exchangecommand line - What library should I use for handling CLI arguments for my Java program? - Software Recommendations Stack Exchange
Java command line parser with subcommands that have similiar options - Software Recommendations Stack Exchange
picocli - a mighty tiny command line interface
How do I parse command line arguments in Java? - Stack Overflow
picocli is different from other Java CLI libraries:
- It is designed to be included in source form. This lets users run picocli-based applications without requiring picocli as an external dependency.
- Generates polished and easily tailored usage help, using ANSI colors when the underlying platform supports it.
- Autocompletion for your Java command line applications on supported platforms
Example usage help message:

Quick overview:
- Effortless command line parsing - just annotate fields
- Strongly typed everything - command line options as well as positional parameters
- full support for both GNU style and POSIX clustered short options (so it handles
<command> -xvfInputFileas well as<command> -x -v -f InputFile) - An arity model that allows a minimum, maximum and variable number of parameters, e.g,
"1..*","3..5" - Subcommands
- Works with Java 5 and higher
- Well-structured user manual
Usage help is the face of your application, so be creative and have fun!

Update:
Picocli is also actively maintained. Since the original post, many new features were added, for example:
- programmatic API as well as annotations API
- Dependency Injection container integration
- JLine integration: delegate to AutoComplete for your command’s Completer implementation
- interface methods can be annotated with
@Optionor@Parameters(picocli creates a synthetic implementation that returns the matched options) - class methods can be annotated with
@Optionor@Parameters(so you can validate options and positional parameters) - support for
@Commandmethods for extra compact code - internationalization with resource bundles
Disclaimer: I am the author.
I recommend JOpt Simple. It 'attempts to honor the command line option syntaxes of POSIX getopt() and GNU getopt_long().' It has community traction and notably is the command line parsing lib of choice for the OpenJDK itself.
For comparison, here's a relatively up to date (as of Jan 2015) list of related libraries that serve the same purpose.
- picocli (with ANSI colors and autocomplete)
- JArgs
- Jakarta Commons CLI
- TE-Code (it has a command line parsing library.)
- argparser
- Java port of GNU getopt
- Args4J
- JSAP
- JOpt Simple
- CLAJR
- CmdLn
- JewelCli
- JCommando
- parse-cmd
- JCommander
picocli supports nested subcommands to arbitrary depth.
CommandLine commandLine = new CommandLine(new MainCommand())
.addSubcommand("cmd1", new ChildCommand1()) // 1st level
.addSubcommand("cmd2", new ChildCommand2())
.addSubcommand("cmd3", new CommandLine(new ChildCommand3()) // 2nd level
.addSubcommand("cmd3sub1", new GrandChild3Command1())
.addSubcommand("cmd3sub2", new GrandChild3Command2())
.addSubcommand("cmd3sub3", new CommandLine(new GrandChild3Command3()) // 3rd
.addSubcommand("cmd3sub3sub1", new GreatGrandChild3Command3_1())
.addSubcommand("cmd3sub3sub2", new GreatGrandChild3Command3_2())
// etc
)
);
You may also like its usage help with ANSI styles and colors.
Note that usage help lists the registered subcommands in addition to options and positional parameters.

The usage help is easily customized with annotations.

- annotation-based
- git-style subcommands
- nested sub-subcommands
- strongly typed option parameters
- strongly typed positional parameters
- customizable type conversion
- multi-value options
- intuitive model for how many arguments a field consumes
- allows any option prefix
- fluent API
- POSIX-style clustered short options
- GNU style long options
- ANSI colors in usage help
- customizable usage help
- single source file: include as source to keep your application a single jar
Which command line arguments parser supports these requirements?
From the limited information in your question the following appear to match your needs.
JOpt Simple
JOpt Simple is a Java library for parsing command line options, such as those you might pass to an invocation of javac.
In the interest of striving for simplicity, as closely as possible JOpt Simple attempts to honor the command line option syntaxes of POSIX getopt() and GNU getopt_long(). It also aims to make option parser configuration and retrieval of options and their arguments simple and expressive, without being overly clever.
The JOpt Simple web page also lists a number of other Java Commandline Parsers which may also be suitable if JOpt Simple is not sophisticated enough for you:
Here are some libraries that perform the same duties as JOpt Simple:
JArgs Jakarta Commons CLI TE-Code has a command line parsing library. argparser Java port of GNU getopt Args4J JSAP CLAJR CmdLn JewelCli JCommando parse-cmd JCommander plume-lib Options
The website contains links for the above if you want to investigate them further.
Source JOpt Simple
Apache 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 -Djava.net.useSystemProxies=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
Source Apache Commons CLI
Check these out:
- http://commons.apache.org/cli/
- http://www.martiansoftware.com/jsap/
Or roll your own:
- http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html
For instance, this is how you use commons-cli to parse 2 string arguments:
import org.apache.commons.cli.*;
public class Main {
public static void main(String[] args) throws Exception {
Options options = new Options();
Option input = new Option("i", "input", true, "input file path");
input.setRequired(true);
options.addOption(input);
Option output = new Option("o", "output", true, "output file");
output.setRequired(true);
options.addOption(output);
CommandLineParser parser = new DefaultParser();
HelpFormatter formatter = new HelpFormatter();
CommandLine cmd = null;//not a good practice, it serves it purpose
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
System.out.println(e.getMessage());
formatter.printHelp("utility-name", options);
System.exit(1);
}
String inputFilePath = cmd.getOptionValue("input");
String outputFilePath = cmd.getOptionValue("output");
System.out.println(inputFilePath);
System.out.println(outputFilePath);
}
}
usage from command line:
$> java -jar target/my-utility.jar -i asd
Missing required option: o
usage: utility-name
-i,--input <arg> input file path
-o,--output <arg> output file
Take a look at the more recent JCommander.
I created it. I’m happy to receive questions or feature requests.