jar 包maven依赖
commons-cli
commons-cli
1.2
package pres.ndz.simple;
import org.apache.commons.cli.*;
/**
* Hello world!
*
*/
public class App {
public static void main(String[] args) throws ParseException {
CommandLineParser parser = new BasicParser();
Options options = new Options();
// 使用 $ java -jar App.jar -h
options.addOption("h","help",false,"help info");
// $java -jar App.jar --file test.txt
options.addOption("f","file",true,"file output");
CommandLine commandLine = parser.parse(options,args);
if (commandLine.hasOption("h")){
System.out.println("Help Message");
System.exit(0);
}
if (commandLine.hasOption("f")){
System.out.println(commandLine.getOptionValue("f"));
}
}
}
标签:JAVA,file,commandLine,jar,System,命令行,Java,options,cli
来源: https://www.cnblogs.com/jzsg/p/10926959.html