[关闭]
@ghimi 2018-10-21T03:28:21.000000Z 字数 785 阅读 871

如何修改 maven 的默认版本

maven


问题:

  1. 创建 maven 项目的时候,jdk 版本是 1.5 版本,而自己安装的是 1.7 或者 1.8 版本.
  2. 每次右键项目名-maven->update project 时候,项目 jdk 版本变了,变回 1.5 版本或者其他版本

解决方法:

解决方法一:在项目中的 pom.xml 指定 jdk版本,如下:

  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. <configuration>
  8. <source>1.8</source>
  9. <target>1.8</target>
  10. </configuration>
  11. </plugin>
  12. </plugins>
  13. </build>

这个方法只能保证该项目的 jdk1.8 版本,每次新建项目都得加上上面代码,不推荐使用,推荐第二种方法.

解决方法二: 在 maven 的安装目录找到 settings.xml 文件,在里面添加如下代码

  1. <profile>
  2. <id>jdk-1.8</id>
  3. <activation>
  4. <activeByDefault>true</activeByDefault>
  5. <jdk>1.8</jdk>
  6. </activation>
  7. <properties>
  8. <maven.compiler.source>1.8</maven.compiler.source>
  9. <maven.compiler.target>1.8</maven.compiler.target>
  10. <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
  11. </properties>
  12. </profile>
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注