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]  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 以上:

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


參考資料


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM