java - 为什么我无法使用 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();
}
}
解决方案
您可以运行Run -> Edit Configuration -> Program arguments -> -name_of_arg value_of_arg。
推荐阅读
- scala - Rdd SPARK 的 Rdd
- c# - 使用列名从excel中读取数据并插入到C#中的SQL表中
- vba - 使用 VBA 将单词列表转换为 Word 表格中的单元格
- java - 无法使用 Morphia (MongoDB) 查询嵌套对象
- javascript - Vuejs 和 Webpack 5 Federation 打字稿错误
- python - 如何清理列表和熊猫数据框中的元素列表?
- python - Python 字典似乎正确,但不起作用
- pagespeed - 为什么我的最大内容绘画比我的页面加载时间大得多?
- ios - Xcode 12 中的“隐藏或显示调试区域”图标在哪里?
- excel - 两列上的 Excel V-LOOKUP 与一列上最接近的匹配