[英]Why I can't parse Options with using Apache CLI
我的问题是,当我创建Options
实例并设置数据时,它无法从我的静态字段"ITEM_COUNT"
读取值。 不明白这是什么问题?
public class Main {
public static final String ITEM_COUNT = "100";
public static void main( String [] args ) throws ParseException, FileNotFoundException {
Options options = new Options();
options.addOption(ITEM_COUNT, true, "The number of items being simulated" );
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse( options, args );
// there I have NumberFormatException:null, the value from ITEM_COUNT is null
Integer item_count = Integer.valueOf(cmd.getOptionValue(ITEM_COUNT));
Runner mockServer = new Runner();
mockServer.initialize(item_count);
mockServer.start();
}
}
您可以运行运行->编辑配置->程序参数-> -name_of_arg value_of_arg 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.