1. 程式人生 > >Eclipse Maven 編譯錯誤 Dynamic Web Module 3.0 requires Java 1.6 or newer 解決方案 (特別注意))

Eclipse Maven 編譯錯誤 Dynamic Web Module 3.0 requires Java 1.6 or newer 解決方案 (特別注意))

Eclipse Maven 開發一個 jee 專案時,編譯時遇到以下錯誤
DescriptionResourcePathLocationType
Dynamic Web Module 3.0 requires Java 1.6 or newer. bdpline 1 Maven Java EE Configuration Problem


DescriptionResourcePathLocationType
One or more constraints have not been satisfied. bdpline 1 Maven Java EE Configuration Problem

如圖:
Dynamic Web Module 3.0 requires Java 1.6 or newer

但是 Eclipse 明明已經將編譯級別設定為 1.7:
Eclipse compiler
這是由於你的 Maven 編譯級別是 jdk1.5 或以下,而你匯入了 jdk1.6 以上的依賴包:檢視 Eclipse 的 Navigator 檢視下該專案的 .classpath 檔案:
[html] view plain copy print?
  1. <classpathentrykind="con"path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"
    >
  2.     <attributes>
  3.         <attributename="maven.pomderived"value="true"/>
  4.     </attributes>
  5. </classpathentry>

解決辦法
使用 maven-compiler-plugin 將 maven 編譯級別改為 jdk1.6 以上:
[html] view plain copy print?
  1. <build>
  2.     <plugins>
  3.         <!-- define the project compile level -->
  4.         <plugin>
  5.             <groupId>org.apache.maven.plugins</groupId>
  6.             <artifactId>maven-compiler-plugin</artifactId>
  7.             <version>2.3.2</version>
  8.             <configuration>
  9.                 <source>1.7</source>
  10.                 <target>1.7</target>
  11.             </configuration>
  12.         </plugin>
  13.     </plugins>
  14. </build>

參考資料