Java Spring MVC 无法在 Heroku 上启动应用程序。错误 H10(找不到 webapp 运行程序)

标签 java spring maven heroku

我尝试在 Heroku 上运行我的应用程序,但它不起作用。从日志中我可以看到以下内容:

2016-01-18T13:38:31.621218+00:00 heroku[web.1]: Process exited with status 1 2016-01-18T13:38:48.101117+00:00 app[web.1]: Error: Unable to access jarfile target/dependency/webapp-runner-8.0.30.1.jar

2016-01-18T13:38:48.100249+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.

2016-01-18T13:38:48.700243+00:00 heroku[web.1]: State changed from starting to crashed 2016-01-18T13:43:12.241285+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=macfol.herokuapp.com request_id=c6418015-843d-4f5a-8dde-83130e94a7c6 fwd="159.220.74.5" dyno= connect= service= status=503 bytes=

我一直在尝试修改 pom.xml 和 procfile,以便 Heroku 最终找到该 .jar,但没有成功。

有 procfile:

web:    java $JAVA_OPTS -jar target/dependency/webapp-runner-8.0.30.1.jar --target/kamienica

还有 pom.xml

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <modelVersion>4.0.0</modelVersion>
    <groupId>kamienica</groupId>
    <packaging>war</packaging>
    <version>1.0.0</version>
    <name>Kamienica</name>

    <properties>
        <springframework.version>4.0.6.RELEASE</springframework.version>
        <hibernate.version>4.3.6.Final</hibernate.version>
        <mysql.version>5.1.31</mysql.version>
        <joda-time.version>2.3</joda-time.version>
        <testng.version>6.9.4</testng.version>
        <mockito.version>1.10.19</mockito.version>
        <h2.version>1.4.187</h2.version>
        <dbunit.version>2.2</dbunit.version>
    </properties>

    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${springframework.version}</version>
        </dependency>

        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <!-- jsr303 validation -->
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.1.3.Final</version>
        </dependency>

        <!-- MySQL -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>

        <!-- Joda-Time -->
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>${joda-time.version}</version>
        </dependency>

        <!-- To map JodaTime with database type -->
        <dependency>
            <groupId>org.jadira.usertype</groupId>
            <artifactId>usertype.core</artifactId>
            <version>3.0.0.CR1</version>
        </dependency>

        <!-- Servlet+JSP+JSTL -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
            <scope>compile</scope>
        </dependency>

        <!-- Testing dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${springframework.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>${testng.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>${h2.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>dbunit</groupId>
            <artifactId>dbunit</artifactId>
            <version>${dbunit.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- for rest -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.4.1.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.4.1</version>
        </dependency>
        <!-- Spring Security -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>4.0.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>4.0.3.RELEASE</version>
        </dependency>


        <dependency>
            <groupId>com.github.jsimone</groupId>
            <artifactId>webapp-runner</artifactId>
            <version>8.0.30.1</version>
        </dependency>

    </dependencies>

    <repositories>
        <repository>
            <id>spring-snapshot</id>
            <name>Spring Snapshot Repository</name>
            <url>http://repo.springsource.org/snapshot</url>
        </repository>
    </repositories>
    <build>
        <pluginManagement>
            <plugins>


                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <warSourceDirectory>src/main/webapp</warSourceDirectory>
                        <warName>Kamienica</warName>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>


                <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>com.github.jsimone</groupId>
                                        <artifactId>webapp-runner</artifactId>
                                        <version>8.0.24.0</version>
                                        <destFileName>webapp-runner.jar</destFileName>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

            </plugins>
        </pluginManagement>
        <finalName>Kamienica</finalName>
    </build>
    <artifactId>Kamienica</artifactId>
</project>

可以在 Maven 依赖项中找到“丢失”的 jar。

感谢您的帮助

编辑 procfile 现在是:

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

没有结果...

编辑2

有一些进展,因为它在其他地方崩溃了;)

enter image description here

编辑3 它正在工作!感谢大家让这一切成为可能。我的应用程序终于出现了。我花了 12 个月才达到这一点。 再次感谢你! :)

最佳答案

  1. 首先删除开头 <pluginManagement>并结束<pluginManagement/>标签 pom.xml (不要删除里面的内容)。通过包含此,dependency目录和 webapp-runner-8.0.30.1.jar不会创建应用程序,并且在执行 java 命令时应用程序崩溃。

  2. 更改 finalName标记为<finalName>kamienica</finalName> 。现在 K 中有大写字母( <finalName>...</finalName> )标签。将其更改为您在 web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/kamienica.war 中命名的小写字母

  3. 将名称更改为 <warName>kamienica</warName>maven-war-plugin插件

               <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <warSourceDirectory>src/main/webapp</warSourceDirectory>
                        <warName>kamienica</warName>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>
    

关于Java Spring MVC 无法在 Heroku 上启动应用程序。错误 H10(找不到 webapp 运行程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34872310/

相关文章:

java - 在eclipse tomcat服务器中启用https不允许调用端口8080

java - 如何在 DataFormatter 中编辑模式?

spring - Spring-MongoDb聚合框架中如何使用$cond操作

maven - Jsch 和 Maven 有什么问题?

java - 如何从我的 java 类构建库文件(jar 文件)?

java - Eclipse 无法解析 LWJGL 引用 (.jar)

spring - Spring 中的@DateTimeFormat 会产生一天后的错误

java - 未找到 Spring-Social 依赖关系

maven-pmd-plugin 禁用一个模块

maven - 未检查存储库