I get a Exception in thread "main" java.lang.NoSuchMethodError: org.apache.commons.cli.Options.hasShortOption(Ljava/lang/String;)Z
while I am trying to create an instance of DefaultParser
.
My code:
Options options = new Options();
// option for day offset
options.addOption(new Option("d", "day", true, "Day offset. -d 7 will
request for last weeks data"));
//options.addOption("d", "day", true, "Day offset. -d 7 will request for last weeks data");
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
Stacktrace:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.commons.cli.Options.hasShortOption(Ljava/lang/String;)Z
at org.apache.commons.cli.DefaultParser.handleShortAndLongOption(DefaultParser.java:491)
at org.apache.commons.cli.DefaultParser.handleToken(DefaultParser.java:243)
at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:120)
at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:76)
at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:60)
at domain.Main.main(Main.java:60)
Line 60 is this:
CommandLine cmd = parser.parse(options, args);
I was just following official apache documentation - https://commons.apache.org/proper/commons-cli/usage.html.
Yes the library can be found within the jar.
Tried running a couple more combinations, which none of them really worked. On the plus side I got a different error. Kind of.
Stacktrace #2
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.commons.cli.Options.getMatchingOptions(Ljava/lang/String;)Ljava/util/List;
at org.apache.commons.cli.DefaultParser.handleLongOptionWithoutEqual(DefaultParser.java:404)
at org.apache.commons.cli.DefaultParser.handleLongOption(DefaultParser.java:384)
at org.apache.commons.cli.DefaultParser.handleToken(DefaultParser.java:239)
at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:120)
at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:76)
at org.apache.commons.cli.DefaultParser.parse(DefaultParser.java:60)
at domain.Main.main(Main.java:61)
That is avro-tools-1.8.2.jar
brings its own version of commons-cli
which conflicts with the version you want to use.
According to the META-INF\DEPENDENCIES
file of avro-tools-1.8.2.jar
it seems to be version 1.2.
Basically you have three options:
commons-cli
that is being used by avro-tools-1.8.2.jar
. I.e. commons-cli-1.2
commons-cli
is on the classpath before avro-tools-1.8.2.jar
avro-tools
and remove the dependency if it is not really needed.If you really need avro-tools
the first option might be the way to go. The seconds option will probably fix the issue in the first place, but might break functionality of avro-tools
because of the conflicting version 1.4 of commons-cli
that will be used. If you don't really need avro-tools
(not talking about avro
but the tools
jar specifically) I'd recommend to remove the avro-tools
dependency. avro-tools
doesn't seem to be suited to be pulled as dependency but is more a standalone application. It bundles a bunch of external libraries that all might end up causing version conflicts on your side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With