gpt4 book ai didi

具有 maven 依赖项的 Java ClassNotFoundException

转载 作者:IT老高 更新时间:2023-10-28 20:51:54 24 4
gpt4 key购买 nike

当我尝试使用 maven 定义的依赖项运行我的应用程序时,我收到 ClassNotFoundExceptionNoClassDefFoundError 异常。

我将我的 Maven 依赖项添加到我的 pom.xml 文件中,声明如下:

<dependency>
<groupId>spy</groupId>
<artifactId>spymemcached</artifactId>
<version>2.8.4</version>
<scope>provided</scope>
</dependency>

这会将相关的 JAR 文件添加到我在 Eclipse 中的 Maven Dependencies 文件夹中。我可以在代码中访问这些类,但是一旦我运行应用程序就会得到上述异常。

在我的 Java 构建路径中引用了 Maven 依赖项下的 jar:

Java build path

我的本​​地 maven 存储库已添加到我的类路径中:

screenshot

当我尝试运行应用程序时,出现以下两个异常:

java.lang.NoClassDefFoundError: Lnet/spy/memcached/MemcachedClient;

java.lang.ClassNotFoundException: net.spy.memcached.MemcachedClient

谁能指出我正确的方向?

最佳答案

provided改为compile

提供

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.

关于具有 maven 依赖项的 Java ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12811392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com