Heroku上的Java Spring MVC错误:无法访问jarfile target / dependency / webapp-runner.jar

时间:2018-11-13 14:09:20

标签: java postgresql heroku jar webapp-runner

我使用Heroku在PostgreSQL数据库中部署Spring MVC Java应用程序。链接到数据库工作良好,并且PostgreSQL已成功初始化。

部署成功,没有错误或看起来奇怪的警告消息,但是现在应用程序失败了。

以下是日志:

    heroku[web.1]: State changed from crashed to starting
    heroku[web.1]: Starting process with command `java $JAVA_OPTS -Dspring.profiles.active="datajpa,heroku" -DMISIC_ROOT="." -jar target/dependency/webapp-runner.jar --port 28363 target/*.war`
    heroku[web.1]: State changed from starting to crashed
    heroku[web.1]: Process exited with status 1
    app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
    app[web.1]: Error: Unable to access jarfile target/dependency/webapp-runner.jar
    heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=misic.herokuapp.com request_id=a242ee89-5594-4f48-9d14-432d46b17600 fwd="178.21.66.110" dyno= connect= service= status=503 bytes= protocol=https

我在stackoverflow上找不到任何答案,可以解决我的问题。 为什么Heroku找不到webapp-runner.jar,我不知道! 在localhost上,一切正常。

我的pom.xml(部分)

    <profiles>
        <profile>
            <id>postgres</id>
            <dependencies>
                <dependency>
                    <groupId>org.postgresql</groupId>
                    <artifactId>postgresql</artifactId>
                    <version>${postgresql.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.tomcat</groupId>
                    <artifactId>tomcat-jdbc</artifactId>
                    <version>${tomcat.version}</version>
                     <scope>provided</scope>
                </dependency>
            </dependencies>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>heroku</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>2.10</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.29.0</version>
                                        <destFileName>webapp-runner.jar</destFileName>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
        <dependencies>
            <dependency>
                <groupId>org.postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>${postgresql.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-jdbc</artifactId>
                <version>${tomcat.version}</version>
            </dependency>
        </dependencies>
    </profile>
</profiles>

版本Tomcat:         8.5.29

Procfile:

    web: java $JAVA_OPTS -Dspring.profiles.active="datajpa,heroku" -DMISIC_ROOT="." -jar target/dependency/webapp-runner.jar --port $PORT target/*.war

链接到Github:https://github.com/MisicSlavisa/misic


我解决了这个问题。由于某种原因,Heroku不使用文件setsings.xml。当我将该文件的内容传输到pom.xml并将其删除时,一切正常。

3 个答案:

答案 0 :(得分:1)

请确保您的pom.xml中有类似的内容:

        <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.13.0</version>
                                <destFileName>webapp-runner.jar</destFileName>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>

有关更多信息,请参见Deploying Tomcat-based Java Web Applications with Webapp Runner

答案 1 :(得分:0)

对我来说1)在尝试设置通过git而不是通过jarfile部署的jhipster upp时,我已经遇到了问题。我之所以拥有它,是因为Node.js buildpack是在Java的buildpack之前启动的,所以我被迫用heroku:buildpacks add --index 2 heroku/nodejs来设置它们,并且heroku:buildpacks添加--index 1 heroku / java`,但是即使更改了我仍然有同样的错误。 2)然后我意识到我在pom,xml中有jar包装,而不是必需的war包装。将此值更改为pom.xml对我有所帮助。

答案 2 :(得分:0)

请参阅我的答案locate folder where webrunner is,以找到您的Procfile。这是我的配置

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