Java Heroku部署失败

时间:2017-11-18 18:32:27

标签: java maven heroku deployment spark-java

尝试将Java服务器部署到Heroku时,我一直收到此错误。

enter image description here

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 enter image description here

的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>

3 个答案:

答案 0 :(得分:2)

我看到两件有趣的事情。

您的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

这很奇怪,你需要了解的东西。或者将您的版本更改为1.0

版本不必附加SNAPSHOT

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

在我的proc文件中,我定义了一个像这样的端口

-Dport=$PORT

我的完整procfile看起来像这样

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

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

答案 1 :(得分:0)

尝试运行

$ heroku ps:scale web=1

这将确保web dyno正在运行。先前部署中的某些内容可能导致其缩小。

答案 2 :(得分:0)

问题出在:

<!-- 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

相关问题