【发布时间】:2015-11-07 11:48:35
【问题描述】:
我正在尝试将多个参数传递给 java 程序。 Apache Commons CLI 界面已正确设置并且可以正常工作。但是,当我尝试使用
setArgs(Option.UNLIMITED_VALUES),它给了我一个错误
The method setArgs(int) is undefined for the type Options.
我的代码如下所示:
import java.io.Console;
import java.util.Arrays;
import java.io.IOException;
import org.apache.commons.cli.*;
public class main {
public static void main(String[] args) {
@SuppressWarnings("deprecation")
CommandLineParser parser = new BasicParser();
Options options = new Options();
options.setArgs(Option.UNLIMITED_VALUES);
options.addOption("p", true, "Program under test");
options.addOption("o", true, "Oracle");
options.addOption("n", true, "Number of test cases");
try {
CommandLine commandline = parser.parse(options, args);
System.out.println(commandline.getOptionValue("p"));
} catch (ParseException e) {
System.out.println("Command line failed.");
e.printStackTrace();
}
}
}
【问题讨论】:
标签: java command-line-interface apache-commons-cli