Eclipse Maven 編譯錯誤 Dynamic Web Module 3.0 requires Java 1.6 or newer 解決方案

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
如圖:
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

[html]  view plain  copy
 
 print?
  1. <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">  
  2.     <attributes>  
  3.         <attribute name="maven.pomderived" value="true"/>  
  4.     </attributes>  
  5. </classpathentry>  


解決辦法
使用 maven-compiler-plugin 將 maven 編譯級別改成 jdk1.6 以上:apache

[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>  


參考資料eclipse

相關文章
相關標籤/搜索