3

I use Heroku to deploy my Spring MVC java application with PostgreSQL database. Link to database works good, and PostgreSQL was successfuly initialize.

The deployment succeeded with no errors or strange looking warning messages, but now the application fails.

Here are the logs:

    heroku[web.1]: State changed from crashed to starting
    heroku[web.1]: Starting process with command `java $JAVA_OPTS -Dspring.profiles.active="datajpa,heroku" -DMISIC_ROOT="." -jar target/dependency/webapp-runner.jar --port 28363 target/*.war`
    heroku[web.1]: State changed from starting to crashed
    heroku[web.1]: Process exited with status 1
    app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
    app[web.1]: Error: Unable to access jarfile target/dependency/webapp-runner.jar
    heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=misic.herokuapp.com request_id=a242ee89-5594-4f48-9d14-432d46b17600 fwd="178.21.66.110" dyno= connect= service= status=503 bytes= protocol=https

I did not find any answer on stackoverflow, that would solve my problem. Why Heroku cann't find webapp-runner.jar, I do not know! On localhost everything works perfectly.

My pom.xml (part)

    <profiles>
        <profile>
            <id>postgres</id>
            <dependencies>
                <dependency>
                    <groupId>org.postgresql</groupId>
                    <artifactId>postgresql</artifactId>
                    <version>${postgresql.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.tomcat</groupId>
                    <artifactId>tomcat-jdbc</artifactId>
                    <version>${tomcat.version}</version>
                     <scope>provided</scope>
                </dependency>
            </dependencies>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>heroku</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>2.10</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.29.0</version>
                                        <destFileName>webapp-runner.jar</destFileName>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
        <dependencies>
            <dependency>
                <groupId>org.postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>${postgresql.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-jdbc</artifactId>
                <version>${tomcat.version}</version>
            </dependency>
        </dependencies>
    </profile>
</profiles>

version Tomcat: 8.5.29

Procfile:

    web: java $JAVA_OPTS -Dspring.profiles.active="datajpa,heroku" -DMISIC_ROOT="." -jar target/dependency/webapp-runner.jar --port $PORT target/*.war

Link to Github: https://github.com/MisicSlavisa/misic


I resolved the problem. Heroku, for some reason, does not use file setings.xml. When I transferred the contents of this file to pom.xml and deleted it, everything worked.

Slavisa Misic
  • 31
  • 1
  • 5
  • I realized the Procfile should exist and be properly created on the repo before to try to deploy it on heroku – JPRLCol Jun 18 '19 at 03:05

3 Answers3

1

Make sure you have something like this in your pom.xml:

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

For more info see Deploying Tomcat-based Java Web Applications with Webapp Runner.

codefinger
  • 10,088
  • 7
  • 39
  • 51
0

For me 1) I have faced it when tried to set up jhipster upp to be deployed via git, not via jarfile. I have it because of Node.js buildpack was initiated before the java's ones, so I was forced to set them up with heroku:buildpacks add --index 2 heroku/nodejs and heroku:buildpacks add --index 1 heroku/java` but even afer this change I still had the same error. 2) then I have realized that I have jar packaging in the pom,xml instead of required war packaging. Changing this value into pom.xml helped me.

Eljah
  • 4,188
  • 4
  • 41
  • 85
0

See my answer locate folder where webrunner is for your Procfile to locate it. Here is my configuration

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals><goal>copy</goal></goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.github.jsimone</groupId>
                                <artifactId>webapp-runner</artifactId>
                                <version>9.0.24.0</version>
                                <destFileName>webapp-runner.jar</destFileName>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        </plugins>
    </build>
tksilicon
  • 3,276
  • 3
  • 24
  • 36