【问题标题】:Error When Building App with Maven Using Heroku使用 Heroku 使用 Maven 构建应用程序时出错
【发布时间】:2021-03-25 15:15:49
【问题描述】:

我正在尝试使用 Heroku 部署我的 Discord 机器人,但每次部署它时都会出现错误。该代码使用 IntelliJ Idea 在本地工作。谁能帮我纠正这个错误?

构建日志:

       [INFO] Changes detected - recompiling the module!
       [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
       [INFO] Compiling 21 source files to /tmp/build_8fdb6208/target/classes
       [INFO] ------------------------------------------------------------------------
       [INFO] BUILD FAILURE
       [INFO] ------------------------------------------------------------------------
       [INFO] Total time:  9.237 s
       [INFO] Finished at: 2021-03-21T23:52:06Z
       [INFO] ------------------------------------------------------------------------
       [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project CalciteDiscordBot: Fatal error compiling: invalid target release: 15 -> [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

这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>CalciteDiscordBot</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.target>15</maven.compiler.target>
        <maven.compiler.source>15</maven.compiler.source>
    </properties>
         
    <dependency>
        <groupId>net.dv8tion</groupId>
        <artifactId>JDA</artifactId>
        <version>4.2.0_168</version>
    </dependency>
    <repository>
        <id>jcenter</id>
        <name>jcenter-bintray</name>
        <url>https://jcenter.bintray.com</url>
    </repository>
</project>

【问题讨论】:

    标签: java maven heroku


    【解决方案1】:

    昨天有人刚刚帮我解决了这个问题,您的 Maven POM 指定您需要 Java 15,但安装的 Java 版本无法处理 15 的编译。因此,使用以下内容将 system.properties 文件添加到您的应用程序根目录并构建再次:

    java.runtime.version=15 
    

    【讨论】:

      【解决方案2】:

      您的应用程序需要 Java 15 (&lt;maven.compiler.source&gt;15&lt;/maven.compiler.source&gt;),因此您需要告诉 Heroku 您需要特定的 Java 版本(而不是默认版本)

      在根文件夹中放置一个文件system.properties:

      java.runtime.version=15
      

      【讨论】:

      • 我创建了一个 system.properties 文件并将 java.runtime 更改为 15,因为我现在使用的是 JDK 15 并且它构建成功。但是,如果我单击“手动部署”部分中“部署到 Heroku”下方的“查看”,则会弹出一个页面:link。该应用程序也不起作用。请您进一步详细说明好吗?这是我的构建日志:link.
      • Procfile declares types -&gt; Worker 这意味着它是一个后台线程。如果您需要从 Web 访问它,您需要定义一个 Web Dyno,使用 Procfile
      • 哦,对不起,我误解了“视图”的含义。我以为这就是您查看应用程序日志的方式,但我错了(抱歉)。构建工作,但是一旦我查看来自Resources -&gt; More -&gt; View Logs 的日志,它会说:link。我想这意味着类没有正确导入,有没有办法解决这个问题?
      • 最好将日志(来自 Heroku)作为文本添加到问题中。它看起来像一个编译错误(不仅仅是依赖)
      • 哦,非常抱歉。这是构建日志:link。这是Resources -&gt; More -&gt; View Logs 日志:link(我也确实重新生成了机器人令牌,因为它在日志中)。
      猜你喜欢
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 2013-08-13
      • 2014-08-16
      • 2012-05-18
      • 2014-05-24
      • 2021-04-10
      • 1970-01-01
      相关资源
      最近更新 更多