Dynamic Web Module 3.0 requires Java 1.6 or newer

Description

在使用 Eclipse 创建 Maven 项目的时候报错 Dynamic Web Module 3.0 requires Java 1.6 or newer,已经确认了 JRE System Library 和 Java Compiler 的版本都是 jdk1.7.0_75,但这个错始终没有消除。

             

Caused By

当前 Maven 默认的 source 设置是 1.5,target 设置是 1.5,不依赖于你 run Maven 所使用的 jdk 版本。如果你想改变这些默认值,你应该按照这里 Setting the -source and -target of the Java Compiler 设置 source 和 target。

Solution

有时你可能需要把一个项目编译成和你当前使用的 jdk 不同的版本。javac 可以接受命令 -source 和 -target。Compiler Plugin 也可以在编译期间提供这种选择。例如,如果你想启用断言( -source 1.4 ) 并且想使用 JVM1.4 编译( -target 1.4 ),你可以在 POM 文件中加入:

 1 <project>
 2   [...]
 3   <build>
 4     [...]
 5     <plugins>
 6       <plugin>
 7         <groupId>org.apache.maven.plugins</groupId>
 8         <artifactId>maven-compiler-plugin</artifactId>
 9         <version>3.3</version>
10         <configuration>
11           <source>1.4</source>
12           <target>1.4</target>
13         </configuration>
14       </plugin>
15     </plugins>
16     [...]
17   </build>
18   [...]
19 </project>

所以在这里我们只需把版本设置为 1.7 即可:

 1 <build>
 2     <plugins>
 3         <plugin>
 4             <groupId>org.apache.maven.plugins</groupId>
 5         <artifactId>maven-compiler-plugin</artifactId>
 6         <version>3.1</version>
 7 
 8         <configuration>
 9             <source>1.7</source>
10         <target>1.7</target>
11         </configuration>
12     </plugin>
13     </plugins>
14 </build>

Reference

 

posted on 2015-10-08 20:37  梅山民  阅读(486)  评论(0编辑  收藏  举报

导航