public class TestCommandLineParser {
public static void main(String[] args) {
try {
CommandLineParser commandLineParser = new BasicParser();
Options options = new Options();
options.addOption("h","help",false,"print information");
options.addOption("c","cfg",true,"config absolute path");
CommandLine commandLine = commandLineParser.parse(options,args);
if(commandLine.hasOption("h")){
System.out.println("Usage example: ");
System.out.println( "java -cfg D:\\MyProject\\face2face\\logic\\src\\main\\resources\\logic.xml -log D:\\MyProject\\face2face\\logic\\src\\main\\resources\\log.xml");
System.exit(0);
}
if(commandLine.hasOption("c")){
String cfg = commandLine.getOptionValue("c");
System.out.println("path : "+cfg);
System.exit(0);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
}
13. java的CommandLineParser
最新推荐文章于 2024-06-17 09:41:54 发布