【问题标题】:Java Apache Commons CLI does not find setArgs()Java Apache Commons CLI 找不到 setArgs()
【发布时间】: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


    【解决方案1】:

    setArgs 是与Option 相关的方法而不是Options

    【讨论】:

    • 但是,这会产生另一个问题。现在同一行给了我“无法从类型选项中对非静态方法 setArgs(int) 进行静态引用”。有什么线索吗?
    • 您可能正在静态调用Option.setArgs。在尝试在该类的实例上使用 setArgs 之前创建一个 Option 的实例
    • 你是救生员!谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-02
    • 2013-03-21
    • 1970-01-01
    • 2019-01-03
    • 2016-12-18
    • 2011-01-04
    • 1970-01-01
    相关资源
    最近更新 更多