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

无法将Spring Boot Web Service发布至Azure:invalid target release:17错误

解决SpringBoot发布到Azure时「invalid target release: 17」错误

核心原因

本地执行Maven编译时使用的JDK版本(如Azure CLI环境的JDK11),与项目pom.xml中指定的编译目标版本不匹配,导致编译阶段直接失败,无法完成发布。

解决步骤

1. 统一pom.xml中的编译版本配置

打开项目的pom.xml,确保编译插件的source、target、release版本与你要部署的Java版本一致(比如选择Java11部署,就全部设为11):

方式一:通过属性配置

<properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <maven.compiler.release>11</maven.compiler.release>
</properties>

方式二:直接配置编译插件

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.10.1</version>
            <configuration>
                <source>11</source>
                <target>11</target>
                <release>11</release>
            </configuration>
        </plugin>
    </plugins>
</build>

2. 确保本地Maven使用的JDK版本匹配

  • 执行java -version和mvn -v,确认两者显示的JDK版本一致,且版本号 >= pom.xml中指定的编译目标版本。
  • 如果本地有多个JDK,设置JAVA_HOME环境变量指向目标JDK(比如JDK11),再重新运行发布命令。

3. 确认Azure Web App的Java版本配置

在Azure门户进入你的App Service:

  • 打开「配置」→「常规设置」
  • 确认「Java版本」和「Java虚拟机版本」与你指定的版本一致
  • 检查「启动命令」是否存在硬编码的错误JDK路径

4. 给Maven Azure插件明确指定运行时版本

在pom.xml的Azure Web App插件配置中添加runtime信息,避免版本不匹配:

<plugin>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-webapp-maven-plugin</artifactId>
    <version>2.5.0</version>
    <configuration>
        <runtime>
            <os>Linux</os>
            <javaVersion>Java 11</javaVersion>
            <webContainer>Java SE</webContainer>
        </runtime>
        <!-- 其他已有配置 -->
    </configuration>
</plugin>

5. 清理缓存后重新构建发布

执行以下命令清理旧编译产物,重新构建并发布:

mvn clean package
mvn azure-webapp:deploy -e

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 05:47:58