我的项目是在linux环境中。我想在我的项目中添加 memcached jar 依赖 jar。因此,我在 pom.xml 中添加了以下行,如此处所述。
<repositories>
<repository>
<id>spy</id>
<name>Spy Repository</name>
<layout>default</layout>
<url>http://files.couchbase.com/maven2/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>spy</groupId>
<artifactId>spymemcached</artifactId>
<version>2.8.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
程序构建成功。但是每当我运行项目 jar 时,它都会引发以下异常:
Exception in thread "main" java.lang.NoClassDefFoundError: net/spy/memcached/MemcachedClient
at MemClient.<clinit>(MemClient.java:12)
at MemClientUser.main(MemClientUser.java:18)
Caused by: java.lang.ClassNotFoundException: net.spy.memcached.MemcachedClient
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 2 more
我尝试了以下链接中给出的一些解决方案:
Java ClassNotFoundException with maven dependency,但它没有修复异常。
如何解决此异常?