这是我在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
答案 0 :(得分:2)
我认为这与目标在Heroku上的Java运行时环境和从Maven编译器生成的本地编译代码之间的不匹配有关, / strong>,您正尝试将其推送到Heroku。
根据Heroku的documentation:
Heroku当前默认使用 OpenJDK 8运行您的应用程序。还提供OpenJDK版本9和7。
其他受支持的默认版本为:
因此,您应该确保在 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运行时环境来做到这一点,例如:
system.properties :
java.runtime.version=11
TLDR:
希望有帮助
答案 1 :(得分:0)
在Heroku中部署git项目时遇到了同样的错误。我只是将pom.xml中的java.version从11更改为8,它对我有用。 enter image description here