【发布时间】:2016-01-20 17:40:01
【问题描述】:
我下载了一个示例代码并想运行它,问题是它使用 JCommander 加载一些配置,我没有配置文件但它想加载一个,所以我想知道;我如何使用 JCommander,我阅读了文档,并根据该站点,它是一个用于解析命令行参数的框架,但我真的不明白这意味着什么,这个错误真的让我无法完成我的项目,这是请求的代码对于.conf 文件:
BasicConfigurator.configure(); // TODO: config from options
// Parse the command line options
CliOptions options = new CliOptions();
new JCommander(options, args);
if (StringUtils.isBlank(options.configFile))
{
options.configFile = "/etc/car-counter/car-counter.conf";
}
// Read in the configuration
Wini ini = new Wini();
ini.getConfig().setMultiOption(true);
ini.load(new File(options.configFile));
new DefaultProcessor(ini).process();
这里是 CliOption 类
public class CliOptions
{
@Parameter(names = { "-c", "--config" }, description = "Sets the location of the configuration file.")
public String configFile;
}
【问题讨论】:
-
所以您不需要解析命令行参数,但您仍然希望使用 JCommander? JComamnder 简化了我们编码和处理命令行参数的方式。
-
不是我不这样做,这是我正在尝试运行的示例项目,它是一个 Opencv 示例项目,但不幸的是,在我修复此错误
java.io.FileNotFoundException: C:\etc\car-counter\car-counter.conf (The system cannot find the path specified)由JCommander生成之前,禁止运行它,我想获得有关如何使此代码工作的帮助,对JCommander不感兴趣,但没有它,似乎此示例代码将无法工作,我不会从我应该运行的示例代码中学习我想学习的内容跨度>
标签: java jcommander