gpt4 book ai didi

java - Spark 应用程序在 Heroku 构建后立即崩溃

转载 作者:行者123 更新时间:2023-12-02 11:42:45 25 4
gpt4 key购买 nike

我尝试了无数方法,通过 IntelliJ 中的终端使用 Maven 将 Spark 应用程序部署到 Heroku。 Heroku 不断给我这条消息,我确信它与 Procfile 以及我的 pom.xml 有关。本地运行良好

Heroku 日志:

2018-01-24T21:36:14.000000+00:00 app[api]: Build succeeded
2018-01-24T21:36:41.627318+00:00 heroku[web.1]: Starting process with command `./build/install/ctr39/bin/ctr39`
2018-01-24T21:36:43.283296+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2018-01-24T21:36:43.283383+00:00 app[web.1]: bash: ./build/install/ctr39/bin/ctr39: No such file or directory
2018-01-24T21:36:43.346808+00:00 heroku[web.1]: State changed from starting to crashed
2018-01-24T21:36:43.351771+00:00 heroku[web.1]: State changed from crashed to starting
2018-01-24T21:36:43.330552+00:00 heroku[web.1]: Process exited with status 127
2018-01-24T21:36:50.407076+00:00 heroku[web.1]: Starting process with command `./build/install/ctr39/bin/ctr39`
2018-01-24T21:36:52.612695+00:00 heroku[web.1]: State changed from starting to crashed
2018-01-24T21:36:52.595643+00:00 heroku[web.1]: Process exited with status 127
2018-01-24T21:36:52.533525+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2018-01-24T21:36:52.533776+00:00 app[web.1]: bash: ./build/install/ctr39/bin/ctr39: No such file or directory

我的Procfile:

web: ./build/install/ctr39/bin/ctr39

我一整天都在这里复制和操纵

我的pom.xml

<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.reach.ctr39</groupId>
<artifactId>ctr39</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>ctr39</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core -->
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.7.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.9.1</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>
<!-- Use your own application name -->
<appName>ct39</appName>
<processTypes>
<!-- Tell Heroku how to launch your application -->
<!-- You might have to remove the ./ in front -->
<web>java -jar ./target/ctr39-1.0-jar-with-dependencies.jar</web>
</processTypes>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals><goal>copy</goal></goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.github.jsimone</groupId>
<artifactId>webapp-runner</artifactId>
<version>8.5.11.3</version>
<destFileName>webapp-runner.jar</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

</project>

知道我做错了什么吗?它可能与 Spark 中的端口问题有关,我将文档提供的主文件中的代码片段复制到...

static int getHerokuAssignedPort() {
ProcessBuilder processBuilder = new ProcessBuilder();
if (processBuilder.environment().get("PORT") != null) {
return Integer.parseInt(processBuilder.environment().get("PORT"));
}
return 4567; //return default port if heroku-port isn't set (i.e. on localhost)
}

最佳答案

在上面的 Codefinger 的帮助下,我找到了正确的方向...

我更新了我的 POM.XML ..我摆脱了 web-runner 并添加了

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals><goal>copy-dependencies</goal></goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

然后将我的 Prodfile 更改为...

web: java $JAVA_OPTS -cp target/classes:target/dependency/* com.reach.ctr39.App

我将 Spark 文档中的端口功能保留为相同。感谢你们。希望这对将来的人有所帮助。

关于java - Spark 应用程序在 Heroku 构建后立即崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48432159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com