简体   繁体   English

Heroku构建后,Spark应用程序立即崩溃

[英]Spark app crashes immediately after Heroku build

I have tried countless methods to get a spark app deployed to Heroku with Maven through the terminal in IntelliJ. 我尝试了无数种方法来通过IntelliJ的终端将Maven的Spark应用程序部署到Heroku。 Heroku keeps giving me this message and I'm sure it has something do with the Procfile & maybe my pom.xml. Heroku不断向我发送此消息,并且我确定它与Procfile以及也许与我的pom.xml有关。 It runs fine locally 它在本地运行良好

Heroku logs : 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

my Procfile : 我的Procfile:

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

I have been copying and manipulating here all day 我整天都在这里复制和操作

my pom.xml 我的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>

Any idea what I'm doing wrong? 知道我在做什么错吗? It likely has something to do with the ports issue in Spark and I copied the snippet in my main file the docs provided ... 它可能与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)
    }

With the help of Codefinger above pointing me in the right direction... 在上述Codefinger的帮助下,我向正确的方向指示...

I updated my POM.XML .. I got rid of web-runner and added 我更新了POM.XML ..我摆脱了网络运行程序并添加了

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

and then changed my Prodfile to ... 然后将我的Prodfile更改为...

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

I kept the Port function the same from the Spark documents. 我将Spark文档中的Port函数保持不变。 Thank you guys. 感谢大伙们。 Hope this helps someone in the future. 希望这对以后的人有所帮助。

Try using the following Procfile file: 尝试使用以下Procfile文件:

web: java -jar ./target/ctr39-1.0-jar-with-dependencies.jar

And instead of ProcessBuilder try: 而不是ProcessBuilder尝试:

System.getenv('PORT')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM