maven中如何指定jdk的版本

2025-11-15 20:31:11

1、全局配置

在maven的安装目录${MAVEN_HOME}/conf/找到settings.xml文件,在里面添加如下代码:

<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>

maven中如何指定jdk的版本

2、局部配置

在项目中的pom.xml指定jdk版本

<build>  

    <plugins>  

        <plugin>  

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-compiler-plugin</artifactId>  

                <version>3.7</version>  

                <configuration>  

                    <source>1.8</source>  

                    <target>1.8</target>  

                </configuration>  

            </plugin>  

        </plugins>  

</build>

maven中如何指定jdk的版本

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢