仅供参考:我在Windows计算机上运行此Java程序。我相信这很重要。在指定附加值时Java Apache Common CLI双精灵选项失败
基本上,我有一个问题,指定一个值到双连字符的选项。单连字选项正常工作。
import org.apache.commons.cli.*;
public class Test {
public static void main(String[] args) throws ParseException {
String[] arguments = new String[] { "--input file.txt" };
// create the Options
Options options = new Options();
options.addOption("i", "input", false, "Specify the input file.");
// Create the parser
CommandLineParser parser = new GnuParser();
// Parse the command line
CommandLine cmd = parser.parse(options, arguments);
}
}
程序失败,错误:
Exception in thread "main" org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: --input file.txt
如果我指定的参数作为-i file.txt,没有错误。如果参数是--input,也没有错误。为什么双连字符选项不接受任何值?它与解析器有关,还是我在Windows机器上运行它?
我在这里做错了什么?任何帮助,将不胜感激。
非常感谢。