使用 apache commons cli 无法识别的选项
unrecognized option using apache commons cli
代码段:
Options options = new Options();
options.addOption("h", "help", false, "prints the help content");
options.addOption("f", "fileType", true, "file type");
options.addOption("u", "url", true, "url");
options.addOption("d", "validDate", true, "valid date");
LoadReferenceFileRequest request=new LoadReferenceFileRequest();
LoadReferenceFileResponse response=new LoadReferenceFileResponse();
try{
//Etape 2: Analyse de la ligne de commande
CommandLineParser parser = new DefaultParser();
CommandLine commandLine = parser.parse(options, args);
if(commandLine.hasOption("f") && commandLine.hasOption("u") && commandLine.hasOption("d")) {
String fileType = commandLine.getOptionValue('f');
request.setFileType(fileType);
String url = commandLine.getOptionValue('u');
request.setUrl(url);
String validDate = commandLine.getOptionValue('d');
request.setValidDate(validDate);
loadReferenceFileClientService.validateRequest(request,response);
loadReferenceFileClientService.invokeInternal(request,response);
}else {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "App" , options );
System.exit(1);
}
用于执行代码的错误描述和命令:
java -classpath MyClassPath -f .xml -usr/local/data/osmiumspa/ref/channel.xml -d 20180905
The error:
ERROR StatusLogger Unrecognized format specifier [n]
ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
%d [%thread] %-5level %logger - %msg%n%d [%thread] %-5level %logger - %msg%nError while parsing the command line: Unrecognized option: -f
问题似乎在 CommandLineParser parser = new DefaultParser();
使用 CommandLineParser parser = new GnuParser();
可以解决这个问题
代码段:
Options options = new Options();
options.addOption("h", "help", false, "prints the help content");
options.addOption("f", "fileType", true, "file type");
options.addOption("u", "url", true, "url");
options.addOption("d", "validDate", true, "valid date");
LoadReferenceFileRequest request=new LoadReferenceFileRequest();
LoadReferenceFileResponse response=new LoadReferenceFileResponse();
try{
//Etape 2: Analyse de la ligne de commande
CommandLineParser parser = new DefaultParser();
CommandLine commandLine = parser.parse(options, args);
if(commandLine.hasOption("f") && commandLine.hasOption("u") && commandLine.hasOption("d")) {
String fileType = commandLine.getOptionValue('f');
request.setFileType(fileType);
String url = commandLine.getOptionValue('u');
request.setUrl(url);
String validDate = commandLine.getOptionValue('d');
request.setValidDate(validDate);
loadReferenceFileClientService.validateRequest(request,response);
loadReferenceFileClientService.invokeInternal(request,response);
}else {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "App" , options );
System.exit(1);
}
用于执行代码的错误描述和命令:
java -classpath MyClassPath -f .xml -usr/local/data/osmiumspa/ref/channel.xml -d 20180905 The error:
ERROR StatusLogger Unrecognized format specifier [n]
ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
%d [%thread] %-5level %logger - %msg%n%d [%thread] %-5level %logger - %msg%nError while parsing the command line: Unrecognized option: -f
问题似乎在 CommandLineParser parser = new DefaultParser();
使用 CommandLineParser parser = new GnuParser();
可以解决这个问题