pom.xml 更新后自动修改jre为J2SE-1.5

warning: 这篇文章距离上次修改已过1573天,其中的内容可能已经有所变动。

每次更新Maven的pom.xml后自动修改jre为J2SE-1.5。

然后Eclipse提示“构建路径指定执行环境 J2SE-1.5。工作空间中没有与此环境严格兼容的 JRE”和“The compiler compliance specified is 1.5 but a JRE 13 is used”。手动修改后。问题可以解决。但老改也不是个事。

解决方法一:手动配置maven默认jre

首先编辑 settings.xml 文件
修改第184行左右的 <profile> 部分为你需要的版本,这里以我的JDK1.13为例。

<profile>
    <id>jdk-1.13</id>
    <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.13</jdk>
    </activation>
    <properties>
        <maven.compiler.source>1.13</maven.compiler.source>
        <maven.compiler.target>1.13</maven.compiler.target>
        <maven.compiler.compilerVersion>1.13</maven.compiler.compilerVersion>
    </properties>
</profile>  

解决方法二:修改项目pom.xml文件

在项目的pom.xml文件中添加下面设置,jdk版本修改成需要的版本。

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

OK,搞定问题

评论已关闭