두 가지 방법에 대해 약간 의문이 생깁니다. 이 경우 내가 getOptionValue(optionName)
을 사용하면 내가 명령 줄에 입력 한 인수를받을 수 있나요하지만 optionName.getValue()
Commons CLI getValue() 및 getOptionValue()
getValue를 사용할 때 내가 널 수()
지정된이 옵션의 값을 돌려줍니다 no 값입니다. 어떤 경우
getOptionValue (문자열)
이 옵션으로, 첫 번째 인수를 검색합니다.
당신이 getOptionValue(String)
을 볼 수 있듯이
setValue(String)
메쏘드 같은 것이 없기 때문에 나는 단지 인자와 똑같다고 생각했습니다.
public static void main(final String[] args) {
CommandLine cmd = null;
Option program = Option.builder("p")
.hasArg()
.required(true)
.longOpt("program")
.build();
Options options = new Options();
options.addOption(program);
CommandLineParser parser = new DefaultParser();
try {
cmd = parser.parse(options, args);
}
catch(ParseException exp) {
System.err.println("Parsing failed. Reason: " + exp.getMessage());
}
String[] list;
list = cmd.getArgs();
int argsN = program.getArgs();
String optionValue = cmd.getOptionValue("p");
String value = program.getValue();
System.out.println(argsN);
System.out.println(optionValue);
System.out.println(value);
}
출력은 다음과 같습니다
1
[인수]
널