Maven - 配置默认JDK版本

一、问题

● 创建 maven 项目的时候,jdk 版本是 1.5 版本,而自己安装的是 1.8 版本,从而导致无法使用 Java8 的新功能。

● 每次 右键项目名 -> maven -> update project 时候,项目 jdk 版本就会变回 1.5 版本。

二、解决办法

1)项目级配置:在项目中的pom.xml指定jdk版本 - 只保证当前项目

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
</build>

2)Maven全局配置:修改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>
posted @ 2020-03-16 11:32  ohmok  阅读(648)  评论(0)    收藏  举报