1

I know that there are a lot of questions related to this, but I messed up everything.

I am running my main class and receiving the following error:

Caused by: java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException

In my project I have several pom.xml files and I checked that all of them contains:

        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>1.2</version>
            <scope>provided</scope>
        </dependency>

How can I fix this issue?

halfer
  • 19,824
  • 17
  • 99
  • 186
John Smith
  • 71
  • 1
  • 8
  • 1
    Maybe this helps: https://stackoverflow.com/a/29230903 – tobifasc Mar 31 '23 at 17:58
  • 1
    oke.. `provided` means: you/someone will (have to) provide them!:)..at runtime;) – xerx593 Mar 31 '23 at 17:59
  • @xerx593 Ok. fool me do not get it. Where I can read about this? What will be the steps? I am not asking direct answer as you can see, but at least path to fix it :( – John Smith Mar 31 '23 at 18:04
  • [here](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#dependency-scope) a good entry point... beyond that it is good-important to know/understand your "dev(runtime) stack" as your "dependency structure" – xerx593 Mar 31 '23 at 18:08

1 Answers1

2

I'm not sure why you have "several" pom files. But assuming you're actually using one of those pom.xml's and you have that dependency in it, the issue is this:

You've indicated that your dependency is provided:

<scope>provided</scope>

This means that Maven expects the runtime environment to provide that dependency. You often see it when you're running in a web server environment (eg. Tomcat, Wildfly, etc.) where there will be additional libraries provided by that environment.

In this case, you either need to provide that dependency at runtime, or update your pom to not expect the dependency to be provided and rebuild. Deleting that <scope> is sufficient.

More information about dependency scope can be found in this question and the documentation.

Roddy of the Frozen Peas
  • 14,380
  • 9
  • 49
  • 99
  • As Roddy said, if your runtime (Spring, Quarkus, Liberty, etc.) does not also use, i.e. provide, the required library, then it can't be defined by you as "provided". – Bill Mair Mar 31 '23 at 19:50