[英]Eclipse + Maven + Spring Application: java.lang.NoClassDefFoundError
There are many stackoverflow questions around this subject but, they surprisingly don't seem to address my situation. 关于这个问题有很多stackoverflow问题,但是令人惊讶的是,它们似乎并没有解决我的情况。
I have validated the following things: 我已经验证了以下内容:
My POM.xml 我的POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.springinaction</groupId>
<artifactId>knights</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>knights</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
</dependencies>
</project>
The main class code that does not run. 无法运行的主类代码。
package com.springinaction.knights;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
public class KnightMain {
public static void main(String[] args) throws Exception {
AbstractApplicationContext context = new AnnotationConfigApplicationContext(KnightConfig.class);
Knight knight = (Knight)context.getBean(Knight.class);
knight.embarkOnQuest();
context.close();
}
}
Gist of error: 错误要点:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/env/EnvironmentCapable
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
If you got in your local repository some old artifacts you wish to get rid of, just do this: 如果您在本地存储库中找到了一些希望摆脱的旧工件,请执行以下操作:
dependency:purge-local-repository
dependency:purge-local-repository
That command will clean your local repository, from dependencies that are being used in your project. 该命令将从项目中正在使用的依赖项中清除本地存储库。
Look at the description from Maven website: 查看来自Maven网站的描述:
Now, to that: 现在,到:
dependency:copy-dependencies
dependency:copy-dependencies
Look at the description from Maven website: 查看来自Maven网站的描述:
This command will pull from remote repository the necessary dependencies to your local repository. 该命令将从远程存储库中将必要的依赖项拉至本地存储库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.