gpt4 book ai didi

java - Apache CLI 无法识别 Eclipse 中的启动参数

转载 作者:行者123 更新时间:2023-12-01 09:43:26 26 4
gpt4 key购买 nike

我正在尝试解析应用程序中的启动参数,但 apache cli 无法识别它们:

public static void main(String[] args) {

logger.debug(Arrays.toString(args)); // prints

CommandLine cmdLine = null;
HelpFormatter formatter = new HelpFormatter();
CommandLineParser parser = new BasicParser();

Options options = new Options();

options.addOption("k", true, "bla");

try {

cmdLine = parser.parse(options, args);

logger.debug("main - {}", cmdLine.hasOption("k")); // prints false

} catch (ParseException e) {
e.printStackTrace();
}

}

在 Eclispe(Runconfiguration -> Arguments)中,我使用 k=hello 启动应用程序

我的输出:

2016-07-08 15:39:34,840 DEBUG [main] (Main.java:27) - [k=hello]
2016-07-08 15:39:34,862 DEBUG [main] (Main.java:53) - main - false

最佳答案

参数应该是“-k hello”

关于java - Apache CLI 无法识别 Eclipse 中的启动参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38268227/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com