13. java的CommandLineParser

版权声明:作者:changshuchao https://blog.csdn.net/changshuchao/article/details/88407024
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();
        }


    }

}

猜你喜欢

转载自blog.csdn.net/changshuchao/article/details/88407024