Heroku无法找到webapp-runner.jar

时间:2017-03-21 15:23:51

标签: java maven heroku

我有一个Spring Web应用程序,我想部署到Heroku。这是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>

这是项目根目录中的Procfile:

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

本地一切都很好,我成功地把它推到了heroku。 Git输出:

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.        

然后heroku日志告诉我:

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

我试图在Procfile中清理并运行确切的命令,一切都在我的本地机器上运行正常。那么这里有什么问题呢?

3 个答案:

答案 0 :(得分:3)

运行此命令以更改buildpack:

$ heroku buildpacks:set heroku/java

再次git push

目前,您的应用正在使用JVM buildpack,它不会运行Maven。当您尝试heroku deploy:war或Heroku Maven插件时,它可能就是这样。

答案 1 :(得分:0)

我偶然发现了这个问题。这是我的pom.xml构建目标。

<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>

就我而言,根据复制目标,目标文件夹中的webrunner位于名为endorsed的目录中。

 <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>

因此,从以下位置更改Procfile:

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

收件人:

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

因此您可以在运行war文件时找到webrunner。

答案 2 :(得分:0)

事实证明,我的问题是我的 .gitignore 文件中有 target 文件夹。

我知道这很愚蠢,但对于任何绝望的人,请仔细检查一下,这不是您的问题。