java命令行参数解析_Java中命令行参数解析

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)

Maven仓库

commons-cli

commons-cli

1.3

Example:

如果想要得到下面的一个参数列表:

java wordcount [-help] [-O][value] [-c] otherfilename

//演示使用的是1.3的版本

public static void main(String[] args) throws IOException, ParseException {

你可能感兴趣的:(java命令行参数解析)