3
votes

I'm deploying a Spring MVC app to Heroku using jetty-runner.jar, but I get an error in the deployment. The Heroku logs only show:

Error: unable to access jarfile target/dependency/jetty-runner.jar
State changed from starting to crashed
Process exited with status 1

However, the app is working correctly if I run it locally using either:

heroku local web -f Procfile.windows

or

java -jar target\dependency\jetty-runner.jar target\*.war

The file under "target/dependency/jetty-runner.jar" is created correctly in my computer when running the "mvn package" command.

My Procfile looks like this:

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

My pom.xml file and project code are located in: https://github.com/gfigueroa/nlp-tools-spring-heroku

ADDITIONAL DETAILS

I ran the command heroku run ls target after deploying and it only shows the .war file. The dependency folder was not created when deploying, even though it was when I packaged my project locally.

2
is the issue resolved? Just wanted to check since I replaced webapp-runner.jar with jetty runner and was able to successfully deploy to heroku.Omkar Puttagunta
What is the output of running heroku run ls target/dependency/jetty-runner.jar?codefinger
@localhost999 Not resolved yet. @codefinger This is what I get: ls: cannot access targetdependencyjetty-runner.jar: No such file...for some reason it's removing the backslashes. (running on Windows by the way).Gerardo Figueroa
@localhost999 I tried it with webapp-runner.jar and it gives me the same error: Unable to access jarfile target/dependency/webapp-runner.jar in the Heroku logs after deploying.Gerardo Figueroa
@codefinger I ran heroku run ls target and it only shows the .war file. The dependency folder and other folders are not created on the Heroku repository as they are locally.Gerardo Figueroa

2 Answers

2
votes

Your maven-clean-plugin is deleting the jar file in dependency directory and other required directories when you try to build your app on Heroku.

You can either remove the maven-clean-plugin in the pom.xml or you can modify it.

Best option is to remove the plugin below in pom.xml

              <plugin>
                  <artifactId>maven-clean-plugin</artifactId>
                  <version>2.5</version>
                  <executions>
                    <execution>
                      <id>clean-jar-artifacts</id>
                      <phase>install</phase>
                      <goals><goal>clean</goal></goals>
                      <configuration>
                        <excludeDefaultDirectories>true</excludeDefaultDirectories>
                        <filesets>
                          <fileset>
                              <directory>target</directory>
                              <excludes>
                                <exclude>*.war</exclude>
                              </excludes>
                          </fileset>
                        </filesets>
                      </configuration>
                    </execution>
                  </executions>
                </plugin>

Or you can exclude the dependency/*.jar from deleting by simply adding the <exclude>..</exclude> tags as specified below. But this option might delete other required folders which are necessary for deploying the app successfully. So I would not recommend this.

    <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>2.5</version>
                    <executions>
                        <execution>
                            <id>clean-jar-artifacts</id>
                            <phase>install</phase>
                            <goals>
                                <goal>clean</goal>
                            </goals>
                            <configuration>
                                <excludeDefaultDirectories>true</excludeDefaultDirectories>
                                <filesets>
                                    <fileset>
                                        <directory>target</directory>
                                        <excludes>
                                            <exclude>*.war</exclude>
                                            <exclude>dependency/*.jar</exclude>
                                        </excludes>
                                    </fileset>
                                </filesets>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

Look at this page for more information.

2
votes

I had the similar problem , until I add into pom.xml file with latest jetty-runner (org.eclipse.jetty)

<plugins>
   <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>org.eclipse.jetty</groupId>
                              <artifactId>jetty-runner</artifactId>
                              <version>9.4.4.v20170414</version>
                       <destFileName>jetty-runner.jar</destFileName>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

Procfile contains only: web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/*.war