【问题标题】:Java Heroku Deployment is failingJava Heroku 部署失败
【发布时间】:2017-11-18 18:32:26
【问题描述】:

我在尝试将 Java 服务器部署到 Heroku 时不断收到此错误。

2017-11-18T18:22:34.252354+00:00 heroku[router]: at=error code=H14 desc="No web 
processes running" method=GET path="/favicon.ico" host=javachatapp-dataserver.herokuapp.com request_id=e899dbbc-1687-470d-a14f-2fffd0cdba12 fwd="24.125.73.190" dyno= connect= service= status=503 bytes= protocol=https

2017-11-18T18:22:34.195269+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=javachatapp-dataserver.herokuapp.com request_id=f3363e55-f850-4235-90e2-6cb6468dc7e5 fwd="24.125.73.190" dyno= connect= service= status=503 bytes= protocol=https

我认为它在配置文件中的路径不正确,因为在 Heroku 构建时,我看到了这个错误:

2017-11-18T01:04:45.763178+00:00 heroku[web.1]: Starting process with command `java -jar ./target/chatappdataserver-1.0-jar-with-dependencies.jar`
2017-11-18T01:04:47.619837+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2017-11-18T01:04:47.620602+00:00 app[web.1]: Error: Unable to access jarfile ./target/chatappdataserver-1.0-jar-with-dependencies.jar

但这确实是我的 Procfile 的内容:

web: java -jar ./target/chatappdataserver-1.0-SNAPSHOT-jar-with-dependencies.jar

当我在 heroku 上登录 bash 并使用上述命令手动启动服务器时,它可以工作,但我似乎无法让 heroku 使用 heroku open 启动服务器。它在每个版本上崩溃。有人见过这个吗?

Heroku 中的Procfile


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>com.wisen.chatappdataserver</groupId>
    <artifactId>chatappdataserver</artifactId>
    <version>1.0-SNAPSHOT</version>


    <dependencies>
        <dependency>
            <groupId>com.sparkjava</groupId>
            <artifactId>spark-core</artifactId>
            <version>2.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <descriptorRefs>
                        <!-- This tells Maven to include all dependencies -->
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.heroku.sdk</groupId>
                <artifactId>heroku-maven-plugin</artifactId>
                <version>0.4.4</version>
                <configuration>
                    <jdkVersion>1.8</jdkVersion>
                    <appName>javachatapp-dataserver</appName>
                    <processTypes>
                        <!-- Tell Heroku how to launch your application -->
                        <web>java -jar ./target/chatappdataserver-1.0-jar-with-dependencies.jar</web>
                    </processTypes>
                </configuration>
            </plugin>
        </plugins>
    </build>



</project>

【问题讨论】:

    标签: java maven heroku deployment spark-java


    【解决方案1】:

    我看到了两件有趣的事情。

    你的 procfile 指的是

    web: java -jar ./target/chatappdataserver-1.0-SNAPSHOT-jar-with-dependencies.jar

    这是合理的,因为您的 pom 将版本定义为 1.0-SNAPSHOT,但 Heroku 尝试根据您共享的日志查找 jar 文件 java -jar ./target/chatappdataserver-1.0-jar-with-dependencies.jar

    这很奇怪,您需要了解一下。或者将您的 pom 中的版本更改为 1.0

    版本不必附加SNAPSHOT

    我认为奇怪的另一件事是您没有指定要使用的端口。 Heroku 动态分配一个端口,然后他们会将来自主机 javachatapp-dataserver.herokuapp.com 的 80 端口的调用路由到这个动态分配的端口。

    在我的 procfile 中,我定义了一个这样的端口

    -Dport=$PORT

    我的完整 procfile 是这样的

    web: java $JAVA_OPTS -Dport=$PORT -jar ./build/libs/tage-1.0-SNAPSHOT-all.jar

    我正在使用 Gradle 构建,因此 jar 文件的路径不同。但这是在这种情况下使用 Maven 和 Gradle 的唯一大区别。

    【讨论】:

    • 因为 pom.xml 文件中的 web 进程指的是:java -jar ./target/chatappdataserver-1.0-jar-with-dependencies.jar。我将其更改为:web: java -jar ./target/chatappdataserver-1.0-SNAPSHOT-jar-with-dependencies.jar,一切正常。
    【解决方案2】:

    尝试运行

    $ heroku ps:scale web=1
    

    这将确保 web dyno 正在运行。以前部署中的某些东西可能导致它缩小。

    【讨论】:

    • 当我运行该命令时,它说找不到该进程类型。我实际上在 heroku 的免费层上,并且已经部署了一个 repo;这可能是它不起作用的原因吗?
    • 您是否使用 Git 进行部署?你的 Procfile 签入了吗?
    • 我使用 maven 部署:mvn heroku: deployheroku open。但是,我第一次部署时,是通过 git:git push heroku masterheroku open。我从 Heroku 中删除了整个 repo,并使用 maven 重新部署。
    • 你的 pom.xml 中有什么配置?
    • 是的,是web process,谢谢你的帮助!
    【解决方案3】:

    问题出在:

    <!-- Tell Heroku how to launch your application -->
    <web>java -jar ./target/chatappdataserver-1.0-jar-with-dependencies.jar</web>
    

    您必须在您的情况下写下您的 artifactId-version-descriptorRef.jar 的名称:chatappdataserver-1.0-SNAPSHOT-jar-with-dependencies.jar

    【讨论】:

      猜你喜欢
      • 2013-04-08
      • 2016-02-21
      • 2014-11-07
      • 1970-01-01
      • 1970-01-01
      • 2019-02-16
      相关资源
      最近更新 更多