使用 Maven 构建应用程序失败,我可以在本地运行代码,但无法在 heroku 上部署 [英] Failed to build app with Maven, I can run code locally, but fail to deploy on heroku

查看:23
本文介绍了使用 Maven 构建应用程序失败,我可以在本地运行代码,但无法在 heroku 上部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is my code in github: https://github.com/q463746583/CS4500-Assignment2 I can run it successfully in the local, but while I try to deploy the code on heroku, There is the error description:

       [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

推荐答案

我认为这与您在 Heroku 上的目标 Java 运行时环境 和您的本地编译的代码,由 Maven 编译器生成, 您正试图将其推送到 Heroku.

I think this has to do with a mismatch between your targeted Java runtime environment on Heroku and your locally compiled code, generated from the Maven compiler, which you're trying to push to Heroku.

根据 Heroku 的文档::em>

Heroku 当前默认使用 OpenJDK 8 来运行您的应用程序.OpenJDK 版本 9 和 7 也可用.

Heroku currently uses OpenJDK 8 to run your application by default. OpenJDK versions 9 and 7 are also available.

其他支持的默认版本有:

Other supported default versions are:

  • 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 运行时环境:

So you should make sure that within your pom.xml file that your maven compiler is compiling your JAVA code to the appropriate JAVA buildpack you're targeting on Heroku. For example, below we are targeting a Java 7 runtime environment:

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 运行时环境来执行此操作,如下所示:

Then you should create a system.properties file in your project if you're targeting a runtime environment other than Heroku's default JDK 1.8 runtime environment. You can do this by specifying your desired java runtime environment like such:

system.properties:

java.runtime.version=11

TLDR:

  1. 确保您使用合适的 JAVA JDK
  2. 检查您的来自 Maven 编译器的目标环境是否与您的目标 Heroku JAVA 运行时相同.
  3. 如果您不使用默认的 JAVA 8 JDK 运行时环境 在您的项目中创建一个 system.properties 文件,指定不同的受支持的 JAVA 运行时环境,如 Heroku 的JAVA buildpack 文档.
  1. Ensure you're using the appropriate JAVA JDK
  2. Check that your target environment from the Maven compiler is the same as your targeted Heroku JAVA runtime.
  3. If you're not using the default JAVA 8 JDK runtime environment create a system.properties file in your project specifying a different supported JAVA runtime enviroment as listed within Heroku's JAVA buildpack documentation.

希望有帮助

这篇关于使用 Maven 构建应用程序失败,我可以在本地运行代码,但无法在 heroku 上部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆