我已经尝试了无数的方法来通过IntelliJ中的终端将Maven部署到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)
}
答案 0 :(得分:1)
在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文档中的Port功能。感谢你们。希望这可以帮助将来的某个人。
答案 1 :(得分:0)
尝试使用以下Procfile
文件:
web: java -jar ./target/ctr39-1.0-jar-with-dependencies.jar
而不是ProcessBuilder
尝试:
System.getenv('PORT')