0

Hi im a bit new to heroku. The app works fine on local but on heroku i get this error when trying to do a rest request on a controller

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>

error logs here LOGS

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=
alexbt
  • 16,415
  • 6
  • 78
  • 87
rogg
  • 11
  • 2

2 Answers2

1

Thanks Alex. The Spring boot guide worked. For the record my pom.xml file looks like this now and i didnt even need a procfile.

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>
rogg
  • 11
  • 2
0

We see the following in your logs:

Starting process with command java -Dserver.port=17355 $JAVA_OPTS -jar target/*.jar

...

Error: Unable to access jarfile target/*.jar

heroku-maven-plugin

I've only used Procfile in the past, but I see that you can also use heroku-maven-plugin to specify the startup command (heroku documentation).

I believe you need to set the <processType> tag in heroku-maven-plugin rather than 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>

Then, deploy with this command: mvn heroku:deploy -Dheroku.appName=myapp

Spring Boot ?

On top of that, I see the dependency spring-boot-starter-web. Is this a spring-boot app ? Then, you shouldn't have the maven-war-plugin and rather build a valid spring-boot archive using spring-boot-maven-plugin (see this example)

If you go down the spring-boot route, you could build it as a Jar and use the following Procfile (placed at the root of your project, with capital P):

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

I think you can wildcard the version, so you don't have to modify the Procfile continuously:

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

Take a look at this: http://nicholaspaulsmith.com/spring-boot-on-heroku/

Community
  • 1
  • 1
alexbt
  • 16,415
  • 6
  • 78
  • 87
  • Yes it is a spring boot project. I was wondering if i could not use procfile whatsoever but ill give it all a try – rogg Oct 22 '16 at 12:40
  • 1
    Thanks a lot. The Spring Boot guide worked. In the end i didnt even need to create a procfile. My rest api works fine now. Thanks – rogg Oct 22 '16 at 19:49