Java ClassNotFoundException with maven dependency

筅森魡賤 提交于 2019-11-27 04:35:27

Change provided to compile

Provided

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

<scope>provided</scope>

"Provided" scope implies that the dependencies should be available only during compile phase and they will be available elsewhere during runtime and Maven shouldn't package them with the rest of the jars and classes of the current application.

Your dependency doesn't seem to be of "provided" scope. Remove that scope from your dependency definition and the jars will be present in your packaged jar/war/ear.

I was facing the same issue but i didn't have the tag defined on my POM, it was always working fine until one day all of a sudden started giving me that error in my local machine for no reason, the dependency was correctly set up in the POM and the jar was present in the local maven repository.

I tried cleaning the project and updating maven project but nothing, none of the other solutions suggested on other posts worked for me either.

I was finally able to solve it by going to the servers tab -> right click on Tomcat v8.0 -> browse deployment location

this should lead you to a temp folder like

.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps

then you browse to your project folder -> WEB-INF -> lib -> here i found out that the jar from the library that was giving the error was missing, so i just copied it from .m2\repository

Restarted the server and it started working as usual again.

I hope this helps some body facing the same issue.

Add below Dependency, It will resolve the Problem.

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-jvm-deps -->
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-jvm-deps</artifactId>
    <version>1.0.3</version>
    <scope>provided</scope>
</dependency>

Answer somewhat related to your problem, but still can help others.
Adding <scope>compile</scope> to the dependency was not enough in my case. I also had to add <packaging>jar</packaging> to the target module's pom.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!