Search code examples
javamavenheroku

Heroku can't find webapp-runner.jar


I've got a Spring web app which I want to deploy to Heroku. Here's the 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

...

<dependencies>

    ...(spring, hibernate, junit, freemarker)

</dependencies>

<build>

    <!-- static final name for easy integration with IDEs -->
    <finalName>web-app</finalName>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.0</version>

            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>

            <configuration>
                <warSourceDirectory>web</warSourceDirectory>
            </configuration>
        </plugin>

        <!-- webapp-runner.jar for running the app -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.8</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.2</version>
                                <destFileName>webapp-runner.jar</destFileName>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>


    </plugins>
</build>
</project>

Here is the Procfile in project root directory:

web:    java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war

Everything is fine locally, and I successfully push it to heroku. Git output:

remote: Compressing source files... done.        
remote: Building source:        
remote: 
remote: -----> JVM Common app detected        
remote: -----> Installing OpenJDK 1.8... done        
remote: -----> Discovering process types        
remote:        Procfile declares types -> web        
remote: 
remote: -----> Compressing...        
remote:        Done: 49.1M        
remote: -----> Launching...        
...
remote: Verifying deploy... done.        

But then heroku logs tells me:

Error: Unable to access jarfile target/dependency/webapp-runner.jar

I tried to clean and run the exact command in the Procfile, and everything went just fine on my local machine. So what can be a problem here?


Solution

  • Run this command to change your buildpack:

    $ heroku buildpacks:set heroku/java
    

    Then git push again.

    Right now, your app is using the JVM buildpack, which doesn't run Maven. It probably got this way when you tried heroku deploy:war or the Heroku Maven plugin.