【问题标题】:Why can't the jarfile be found while deploying on heroku?为什么在heroku上部署时找不到jarfile?
【发布时间】:2023-04-08 11:44:01
【问题描述】:

尝试在 heroku 上部署我的应用时,我不断收到错误消息。

这是我的 pom.xml(构建部分):

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <verbose>true</verbose>
                    <source>1.8</source>
                    <target>1.8</target>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <path>/</path>
                    <contextReloadable>true</contextReloadable>
                </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>
    </build>

这是我的 Procfile:

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

我不断收到此错误:

错误:无法访问 jarfile 目标/依赖项/web-runner.jar 2020-04-27T22:38:02.611229+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=joke-generator76.herokuapp.com request_id=53d259d1 -f2a7-469f-bc09-efb6019f42f1 fwd="89.76.117.177" dyno= connect= service= status=503 bytes= protocol=https 2020-04-27T22:38:02.731866+00:00 heroku[路由器]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=joke-generator76.herokuapp.com request_id=9b168a99-3bd1-4d15-bcf7-da703b4cd070 fwd="89.76.117.177" dyno= connect= service= status=503 bytes= protocol=https

所以,我想,由于某种我无法理解的原因,它无法访问 jarfile。

有人知道问题可能是什么吗?我搜索了所有官方 heroku 的文档、各种开发博客、其他论坛等。我尝试了多种解决方案,但没有任何效果。

如果我发现的信息是可信的,我在这里提供的代码实际上是许多人解决它给我带来的问题的原因。

此外,应用程序在 localhost 上运行没有任何问题。

请帮忙。

【问题讨论】:

    标签: java maven heroku dependencies


    【解决方案1】:

    Procfile jar 文件 (web-runner.jar) 和 POM 文件 destFileName (webapp-runner.jar) 不匹配

    【讨论】:

    • 非常感谢,这个解决方案确实解决了我最初的问题,但现在 heroku 给了我错误 404,说“请求的资源不可用”。日志告诉我:INFO: No global web.xml foundINFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time 知道如果应用程序在本地运行良好,为什么会给我 404? `
    【解决方案2】:

    仅作记录。我完全改变了我的 POM 并完全删除了 Procfile。现在它的功能没有问题。我想我只是深入研究了服务器本身负责的配置。在下面添加我的新 POM:

    <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.2.RELEASE</version>
        </parent>
        <properties>
            <java.version>1.8</java.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-thymeleaf</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    

    它现在在 Heroku 和 localhost 上一样有效。

    【讨论】:

      猜你喜欢
      • 2020-04-12
      • 1970-01-01
      • 1970-01-01
      • 2014-10-06
      • 2017-07-11
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 2021-12-06
      相关资源
      最近更新 更多