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

Java Maven项目部署Heroku报错H10(应用崩溃)无法启动求助

你的H10报错核心是应用启动时无法找到指定的依赖文件、配置存在多处语法错误,具体解决方案如下:

问题根源

  1. pom.xml中没有配置webapp-runner依赖的下载和复制逻辑,导致启动时找不到target/dependency/webapp-runner.jar文件
  2. Procfile中Java大小写错误,Linux系统下命令区分大小写,必须用小写的java
  3. Procfile中–port是全角长破折号,系统无法识别为参数前缀,需要改为半角双横杠--port
  4. 默认maven打包生成的war包名称为trial-1.0-SNAPSHOT.war,和Procfile中指定的target/trial.war不匹配

修复步骤

1. 修正pom.xml配置

首先在build节点下添加finalName配置,确保打包后war包名称和Procfile一致:

<build>
  <finalName>trial</finalName>
  <!-- 原有plugins配置保持不变 -->
</build>

再找到maven-dependency-plugin的executions节点,新增一个execution配置,用于自动下载webapp-runner并复制到指定目录,无需手动安装任何组件:

<execution>
  <phase>package</phase>
  <goals>
    <goal>copy</goal>
  </goals>
  <configuration>
    <outputDirectory>${project.build.directory}/dependency</outputDirectory>
    <artifactItems>
      <artifactItem>
        <groupId>com.heroku</groupId>
        <artifactId>webapp-runner</artifactId>
        <version>9.0.27.0</version>
        <type>jar</type>
      </artifactItem>
    </artifactItems>
  </configuration>
</execution>

2. 修正Procfile内容

替换为以下内容:

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

3. 新增JDK版本声明(可选但建议)

在项目根目录新建system.properties文件,避免Heroku默认高版本JDK和你代码的Java 7编译版本不兼容:

java.runtime.version=1.7

4. 重新部署验证

把所有修改提交后推送到Heroku,部署完成后执行heroku logs --tail即可看到服务正常启动,H10报错消失。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 07:57:02