简体   繁体   English

Heroku 找不到 webapp-runner.jar

[英]Heroku can't find webapp-runner.jar

I've got a Spring web app which I want to deploy to Heroku.我有一个 Spring Web 应用程序,我想将它部署到 Heroku。 Here's the pom.xml:这是 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:这是项目根目录中的Procfile:

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.在本地一切都很好,我成功地将其推送到了heroku。 Git output: 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.        

But then heroku logs tells me:但后来 heroku 日志告诉我:

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.我尝试清理并运行 Procfile 中的确切命令,并且在我的本地机器上一切正常。 So what can be a problem here?那么这里有什么问题呢?

Run this command to change your buildpack:运行此命令以更改您的 buildpack:

$ heroku buildpacks:set heroku/java

Then git push again.然后再次git push

Right now, your app is using the JVM buildpack, which doesn't run Maven.现在,您的应用程序正在使用不运行 Maven 的 JVM buildpack。 It probably got this way when you tried heroku deploy:war or the Heroku Maven plugin.当您尝试使用heroku deploy:war或 Heroku Maven 插件时,它可能会这样。

I stumbled upon this problem.我偶然发现了这个问题。 Here is my pom.xml build goal.这是我的 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>

In my case, the webrunner in the target folder as per copy goal is in a directory named endorsed.就我而言,根据复制目标,目标文件夹中的 webrunner 位于名为已背书的目录中。

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

So change Procfile from:所以改变 Procfile 从:

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

To:到:

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

So the webrunner can be located as you run the war file.因此,可以在运行 war 文件时找到 webrunner。

Turns out, my problem was that I had the target folder in my .gitignore file.原来,我的问题是我的 .gitignore 文件中有target文件夹。

I know that's dumb, but for anyone desperate, double check that, that isn't your problem.我知道这很愚蠢,但是对于任何绝望的人,请仔细检查一下,这不是您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM