import org.apache.commons.cli.*; public class CommandLineParserExample { public static void main(String[] args) { Options options = new Options(); Option option1 = new Option("h", "help", false, "Display help information"); options.addOption(option1); Option option2 = new Option("v", "version", false, "Display version information"); options.addOption(option2); CommandLineParser parser = new DefaultParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { System.out.println("Help information"); } if (cmd.hasOption("version")) { System.out.println("Version 1.0"); } } catch (ParseException e) { System.err.println("Error: " + e.getMessage()); } } } <dependency> <groupId>commons-cli</groupId> <artifactId>commons-cli</artifactId> <version>1.4</version> </dependency>


上一篇:
下一篇:
切换中文