You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Eclipse中使用JDK 17运行pom.xml及配置调整

问题解答

Maven版本是否需要更换?

不用换。Maven 3.9.3本身完全兼容JDK 17及更高版本(官方支持范围是JDK 8到JDK 21),你当前的Maven版本足够支撑JDK 17的构建需求。

如何调整compiler插件?

需要在pom.xml里明确指定编译的JDK版本为17,有两种常用方式:

  1. 通过Maven属性全局配置:
<properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <!-- 推荐用release参数统一指定,避免source/target不一致 -->
    <maven.compiler.release>17</maven.compiler.release>
</properties>
  1. 直接配置maven-compiler-plugin插件:
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <!-- 建议用3.11.0及以上版本,更好兼容JDK 17 -->
            <version>3.11.0</version>
            <configuration>
                <release>17</release>
            </configuration>
        </plugin>
    </plugins>
</build>

如何调整surefire插件?

要确保surefire插件版本足够新,旧版本可能存在JDK 17的兼容性问题,推荐使用3.2.5及以上版本,配置方式如下:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.2.5</version>
            <!-- 如果遇到模块路径相关问题,可添加以下配置 -->
            <configuration>
                <useModulePath>true</useModulePath>
            </configuration>
        </plugin>
    </plugins>
</build>

另外,在Eclipse里也要同步调整项目的JDK配置:右键项目→Properties→Java Build Path→Libraries,确保JRE System Library是JDK 17;同时在Java Compiler里勾选"Use compliance from execution environment 'JavaSE-17' on the 'Execution Environment'",或者直接设置Compiler compliance level为17。

内容的提问来源于stack exchange,提问作者samir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 18:33:13