maven项目jdk版本自动修改
- 新建maven项目的时候jdk版本不对。
- maven 更新后jdk版本默认刷新成别的版本。
第一种解决办法项目单独配置
在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>
第二种解决方法都maven的配置文件进行统一配置(一劳永逸)
-
首先查找到maven的配置文件
maven的配置文件settings.xml存在于两个地方:- 安装的地方:${M2_HOME}/conf/settings.xml(全局目录可以指定仓库的位置)
- 用户的目录:${user.home}/.m2/settings.xml
前者又被叫做全局配置,对操作系统的所有使用者生效;后者被称为用户配置,只对当前操作系统的使用者生效。如果两者都存在,它们的内容将被合并,并且用户范围的settings.xml会覆盖全局的settings.xml。
-
修改maven的配置文件
settings.xml
找的profiles标签添加一下内容:<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>