/** * Extracts all name=value pairs from the command line, sets them all as system properties and also returns * a map of properties containing them. * * @param args The command line. * @param commandLine The command line parser. * @param properties The properties object to inject all parsed properties into (optional may be <tt>null</tt>). * * @return A set of properties containing all name=value pairs from the command line. */ public static Properties processCommandLine(String[] args, CommandLineParser commandLine, Properties properties) { // Capture the command line arguments or display errors and correct usage and then exit. Properties options = null; try { options = commandLine.parseCommandLine(args); // Add all the trailing command line options (name=value pairs) to system properties. They may be picked up // from there. commandLine.addCommandLineToProperties(properties); } catch (IllegalArgumentException e) { System.out.println(commandLine.getErrors()); System.out.println(commandLine.getUsage()); System.exit(1); } return options; }