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

查看:90
本文介绍了无法使用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的文档:

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

因此,您应该确保 maven编译器在 pom.xml 文件中,将您的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天全站免登陆