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>
參考資料