Heroku unable to access jetty-runner jar file

2019-07-04 02:17发布

问题:

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.

回答1:

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:

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