我们普遍会使用maven来编译管理项目,maven不同版本是有自己默认的编译环境,一般默认版本的编译级别比较低。当Eclipse中配置maven后,我们就可以使用maven来编译我们的项目:项目右键maven update,此命令已经集成了maven的compile命令,所以他会使用maven的编译环境来编译项目;
解决的第一种方式:添加maven编译插件指定编译环境,在pom.xml中添加以下代码(插件):
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
2:或者在pom.xml中添加以下属性: