Eclipse Maven 开发一个 jee 项目时,编译时遇到以下错误:
Description Resource Path Location Type
Dynamic Web Module 3.0 requires Java 1.6 or newer. bdp line 1 Maven Java EE Configuration Problem
Description Resource Path Location Type
One or more constraints have not been satisfied. bdp line 1 Maven Java EE Configuration Problem
如图:
但是 Eclipse 明明已经将编译级别设置为 1.7:
这是由于你的 Maven 编译级别是 jdk1.5 或以下,而你导入了 jdk1.6 以上的依赖包:查看 Eclipse 的 Navigator 视图下该项目的 .classpath 文件:
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
解决办法:
使用 maven-compiler-plugin 将 maven 编译级别改为 jdk1.6 以上:
- <build>
- <plugins>
- <!-- define the project compile level -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
dynamic web module 版本之间的区别:
Servlet 3.0 | December 2009 | JavaEE 6, JavaSE 6 | Pluggability, Ease of development, Async Servlet, Security, File Uploading |
Servlet 2.5 | September 2005 | JavaEE 5, JavaSE 5 | Requires JavaSE 5, supports annotations |
Servlet 2.4 | November 2003 | J2EE 1.4, J2SE 1.3 | web.xml |
错误Cannot change version of project facet Dynamic Web Module to 3.0:
在项目右键属性的Project facts中把Dynamci Web Module设置为3.0,如果报错则直接修改项目文件:工程.settings目录下的org.eclipse.wst.common.project.facet.core.xml,同时把web.xml开头设置由2.5改成3.0为:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
然后执行项目右键Maven的Update Project...即可。