Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
640 views
in Technique[技术] by (71.8m points)

Java ClassNotFoundException with maven dependency

I am getting ClassNotFoundException and NoClassDefFoundError exceptions when I attempt to run my application using a maven defined dependency.

I added my maven dependency for the jar in question to my pom.xml file with the following declaration:

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

This added the relevant JAR file to my Maven Dependencies folder in Eclipse. I can access the classes in code but I get the mentioned exceptions once I run the application.

The jar is referenced in my Java build path under Maven dependencies:

Java build path

My local maven repository is added to my classpath:

screenshot

When I attempt to run the application, I get the following two exceptions:

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

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

Can anyone point me in the right direction?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...