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

Heroku忽略system.properties文件,无法切换至JDK 17部署JSP项目

问题

我尝试在Heroku上部署JSP项目,遵循官方指南完成部署步骤。部署时发现Heroku默认使用JDK 1.8,但我的项目需要JDK 17。我创建了system.properties文件并写入java.runtime.version=17,提交推送后Heroku仍尝试用JDK 1.8,请问哪里操作出错了?


项目配置文件

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.ruskaof</groupId>
    <artifactId>lab2WildFly</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>lab2WildFly</name>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.9.0</version>
            </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals><goal>copy</goal></goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.heroku</groupId>
                                    <artifactId>webapp-runner</artifactId>
                                    <version>9.0.52.1</version>
                                    <destFileName>webapp-runner.jar</destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Procfile

web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war

解决方案

  • 检查system.properties位置与格式:确保文件放在项目根目录,且内容仅包含java.runtime.version=17,无多余空格、注释或其他内容,Heroku仅读取根目录的该配置文件。
  • 升级webapp-runner版本:当前使用的webapp-runner:9.0.52.1对应Tomcat 9,仅支持JDK 8-11,不兼容JDK 17。需替换为支持JDK 17的版本,比如webapp-runner:10.1.12.1(对应Tomcat 10.1,兼容JDK 8+至17)。
  • 完善maven-compiler-plugin配置:升级插件版本并添加release参数,确保编译输出完全符合JDK 17规范,修改后配置如下:
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.11.0</version>
        <configuration>
            <source>17</source>
            <target>17</target>
            <release>17</release>
        </configuration>
    </plugin>
    
  • 重新推送并核查日志:修改后执行git add . && git commit -m "适配JDK 17" && git push heroku master,查看Heroku构建日志,确认是否出现Installing JDK 17的记录,排查是否存在文件未提交的问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 13:00:55