public static void main(String[] args) {
CommandLineParser parser = new DefaultParser();
Options options = new Options();
options.addOption("f", "file", true, "Input file");
options.addOption("o", "output", true, "Output file");
try {
CommandLine cmd = parser.parse(options, args);
String inputFile = cmd.getOptionValue("file");
String outputFile = cmd.getOptionValue("output");
// ...
} catch (ParseException e) {
}
}
public static void main(String[] args) {
Options options = new Options();
options.addOption("f", "file", true, "Input file");
options.addOption("o", "output", true, "Output file");
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("mytool", options);
}
try {
// ...
} catch (Exception e) {
}