嗨,我在尝试将我的java maven构建应用程序部署到heroku时遇到错误

时间:2016-10-22 08:46:33

标签: maven heroku spring-boot procfile

嗨,我对heroku有点新鲜。该应用程序在本地工作正常,但在heroku上我尝试在控制器上执行休息请求时出现此错误

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>org.springframework</groupId>
  <artifactId>gs-maven</artifactId>
  <version>0.1.0</version>
  <packaging>war</packaging>

  <name>testing</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>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.4.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20160810</version>
        </dependency>
  </dependencies>

  <build>
        <plugins>
        <!--
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>hello.Application</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warSourceDirectory>src/main/jwebapp</warSourceDirectory>
                    <warName>gs-maven-0.1.0</warName>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <processTypes>
                        <web>
                            java $JAVA_OPTS -cp target/classes:target/dependency/* Application
                        </web>
                    </processTypes>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

错误记录在这里 的 日志

2016-10-22T07:30:13.637732+00:00 heroku[web.1]: State changed from starting to c
rashed

2016-10-22T07:30:13.637732+00:00 heroku[web.1]: State changed from crashed to st
arting

2016-10-22T07:30:18.085285+00:00 heroku[web.1]: Starting process with command `j
ava -Dserver.port=17355 $JAVA_OPTS -jar target/*.jar`

2016-10-22T07:30:19.552462+00:00 heroku[web.1]: Process exited with status 1

2016-10-22T07:30:19.559097+00:00 heroku[web.1]: State changed from starting to c
rashed

2016-10-22T07:30:19.499662+00:00 app[web.1]: Create a Procfile to customize the
command used to run this process: https://devcenter.heroku.com/articles/procfile

2016-10-22T07:30:19.503097+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults
based on dyno size. Custom settings will override them.

2016-10-22T07:30:19.503942+00:00 app[web.1]: Error: Unable to access jarfile tar
get/*.jar

2016-10-22T07:30:39.331500+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/" host=waisserver.herokuapp.com request_id=4249b569-93d2
-4257-adc2-3ddf8577e4fd fwd="188.172.153.178" dyno= connect= service= status=503
 bytes=

2 个答案:

答案 0 :(得分:1)

谢谢Alex。 Spring引导指南有效。为了记录,我的pom.xml文件现在看起来像这样,我甚至不需要proc文件。

<强> 的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>org.springframework</groupId>
  <artifactId>gs-maven</artifactId>
  <version>0.1.0</version>
  <packaging>jar</packaging>

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

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

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.1.RELEASE</version>
</parent>  

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.4.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20160810</version>
        </dependency>
  </dependencies>

  <build>
        <plugins>
        <!--
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>hello.Application</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warSourceDirectory>src/main/jwebapp</warSourceDirectory>
                    <warName>gs-maven-0.1.0</warName>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <processTypes>
                        <web>
                            java $JAVA_OPTS -cp target/classes:target/dependency/* Application
                        </web>
                    </processTypes>
                </configuration>
            </plugin>
            -->
            <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        </plugins>
    </build>


</project>

答案 1 :(得分:0)

我们在您的日志中看到以下内容:

  

使用命令java -Dserver.port=17355 $JAVA_OPTS -jar target/*.jar

启动流程      

...

     

错误:无法访问jarfile target / * .jar

的Heroku-行家-插件

我过去只使用过Procfile,但我发现您也可以使用heroku-maven-plugin来指定启动命令(heroku documentation)。

我认为您需要在<processType>而非heroku-maven-plugin中设置maven-war-plugin代码:

<plugin>
  <groupId>com.heroku.sdk</groupId>
  <artifactId>heroku-maven-plugin</artifactId>
  <configuration>
    <processTypes>
      <web>java $JAVA_OPTS -cp target/classes:target/dependency/* Application</web>
    </processTypes>
  </configuration>
</plugin>

然后,使用此命令进行部署:mvn heroku:deploy -Dheroku.appName=myapp

Spring Boot?

最重要的是,我看到了依赖spring-boot-starter-web。这是一个弹簧启动应用程序?然后,您不应该使用maven-war-plugin而是使用spring-boot-maven-pluginsee this example)构建有效的spring-boot存档

如果你沿着spring-boot路线走下去,你可以把它建成一个Jar并使用以下Procfile(放置在项目的根目录,资本P):

web: java $JAVA_OPTS -Dserver.port=$PORT -jar target/gs-maven-0.1.0.jar

我认为您可以使用通配符版本,因此您无需不断修改Procfile

web: java $JAVA_OPTS -Dserver.port=$PORT -jar target/gs-maven-*.jar

看看这个:http://nicholaspaulsmith.com/spring-boot-on-heroku/