Java command-line argument parser taxonomy

Every once in a while, at the beginning of a new project, I start the search for a command-line argument parsing library in Java. This post shows the results of examining the field as of mid 2018. This post serves both as a “which to use” and as a “which have been evaluated, and found wanting” guide.

* Best So Far
JCommander v1.71
http://jcommander.org/
annotation, good documentation, custom parser, validation

* Honorable Mention
picocli v3.3
http://picocli.info/
annotation, good documentation — documentation looks suspiciously like it is patterned after JCommander

* Pretty Good
args4j
http://args4j.kohsuke.org/
field-based, annotation-based, unclear if “–long-Name” is supported

JewelCLI
http://jewelcli.lexicalscope.com/
annotation-based, interface-based but can be instance-based with setters, has short and long names

* Also-Rans

jopt-simple
https://pholser.github.io/jopt-simple/
Key-Value – the opposite of a good library. Many of the libraries below share this same deficiency.

JArgs
http://jargs.sourceforge.net/
single “parse” call with array of options, Key-Value get value where key is the option

Jakarta Commons CLI
http://commons.apache.org/proper/commons-cli/
like JArgs, except key is “String”, not option object

argparser
http://www.cs.ubc.ca/~lloyd/java/argparser.html
create individual options, where options are “holders”, parse() into the holders

JSAP
http://www.martiansoftware.com/jsap/
old (2008), not well documented

JCommando
http://jcommando.sourceforge.net/
it generates .java, but still requires an additional .jar

This entry was posted in Software Engineering. Bookmark the permalink.