BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); try ...{ args = in.readLine().split(" "); Options opt = new Options(); opt.addOption("h", false, "Print help for this application"); opt.addOption("u", true, "The username to use"); opt.addOption("dsn", true, "The data source to use"); BasicParser parser = new BasicParser(); CommandLine cl = parser.parse(opt, args); if (cl.hasOption("h")) ...{ HelpFormatter f = new HelpFormatter(); f.printHelp("OptionsTip", opt); } else ...{ System.out.println(cl.getOptionValue("u")); System.out.println(cl.getOptionValue("dsn")); } } catch (ParseException e) ...{ e.printStackTrace(); } catch (IOException e) ...{ e.printStackTrace(); } } }上诉代码运行后在控制台输入 -h,显示如下信息:usage: OptionsTip -dsn <arg> The data source to use -h Print help for this application -u <arg> The username to use