gpt4 book ai didi

java - 使用 Maven 构建应用程序失败,我可以在本地运行代码,但无法在 heroku 上部署

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:00:41 24 4
gpt4 key购买 nike

这是我在github中的代码: https://github.com/q463746583/CS4500-Assignment2我可以在本地成功运行它,但是当我尝试在 heroku 上部署代码时,有错误描述:

       [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/com/thoughtworks/qdox/qdox/2.0-M9/qdox-2.0-M9.jar (317 kB at 6.0 MB/s)
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to /tmp/build_3c4f3b86a26f6e3ae1cbe89639f79f26/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.261 s
[INFO] Finished at: 2019-01-24T00:47:07Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project myapp: Fatal error compiling: invalid target release: 11 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
! ERROR: Failed to build app with Maven
We're sorry this build is failing! If you can't find the issue in application code,
please submit a ticket so we can help: https://help.heroku.com/
! Push rejected, failed to compile Java app.
! Push failed

最佳答案

TLDR:

  1. 确保您使用合适的 JAVA JDK
  2. 检查您的 Maven 编译器的目标环境是否与您的目标 Heroku JAVA 运行时相同
  3. 如果您不使用默认的 JAVA 8 JDK 运行时环境在您的项目中创建一个 system.properties 文件,指定一个不同的受支持的 JAVA 运行时环境,如 Heroku 的JAVA 构建包文档。

我认为这与您的Heroku 上的目标 Java 运行时环境 和您的本地编译代码(由 Maven 编译器生成)之间的不匹配有关, 您正在尝试将其推送到 Heroku。

根据 Heroku 的 documentation :

Heroku 目前使用 默认情况下运行您的应用程序的 OpenJDK 8。 OpenJDK 版本 9 和 7 也可用。

其他支持的默认版本是:

  • Java 7 - 1.7.0_181
  • Java 8 - 1.8.0_191
  • Java 9 - 9.0.4
  • Java 10 - 10.0.2
  • Java 11 - 11

因此,您应该确保在您的 pom.xml 文件中,您的 maven 编译器正在将您的 JAVA 代码编译为您在 Heroku 上定位的适当 JAVA buildpack。例如,下面我们的目标是 Java 7 运行时环境:

pom.xml:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

如果您的目标运行时环境不是 Heroku 的默认 JDK 1.8 运行时环境,那么您应该在项目中创建一个 system.properties 文件。您可以通过像这样指定所需的 Java 运行时环境来执行此操作:

系统属性:

java.runtime.version=11

关于java - 使用 Maven 构建应用程序失败,我可以在本地运行代码,但无法在 heroku 上部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54337999/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com