<dependency> <groupId>com.beust</groupId> <artifactId>jcommander</artifactId> <version>1.78</version> </dependency> @Parameters(commandNames = "mycommand", commandDescription = "This is a command") public class MyCommand { @Parameter(names = {"-h", "--help"}, description = "Print this help message") private boolean help; @Parameter(names = {"-f", "--file"}, description = "File path", required = true) private String filePath; // Getters and setters } public static void main(String[] args) { MyCommand myCommand = new MyCommand(); JCommander jCommander = JCommander.newBuilder() .addObject(myCommand) .build(); jCommander.parse(args); if (myCommand.isHelp()) { jCommander.usage(); return; } // ... }


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