Maven项目配置默认JRE/JDK编译版本

来源:互联网 发布:windows清理垃圾命令 编辑:程序博客网 时间:2024/05/18 23:56

PS:

现象:

maven项目在eclipse中一旦update就会把编译的版本变到1.5(即使对Build Path做了修改同样如此)。

解决方案:

在maven的配置文件settings.xml或pom.xml里做如下配置。

(1)settings.xml中的配置是针对所有的项目的,而pom.xml中的配置是针对当前项目的,pom.xml中的配置会覆盖settings.xml中的配置。

(2)配置好之后,在项目的右键菜单中,选中Maven-->update project即可更新项目JRE为新版本。

1、在maven的配置文件settings.xml中的<profiles>标签里添加如下代码,设置默认JRE编译版本为1.8

<profile>  <id>jdk-1.8</id>     <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk>  </activation>     <properties><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>  </properties></profile>
2、在pom.xml的<plugins>中添加如下代码,修改maven默认的JRE编译版本,1.8代表JRE编译的版本。

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.8</source><target>1.8</target></configuration></plugin>


0 0
原创粉丝点击