![](/img/trans.png)
[英]Heroku Java WAR app that was working now failing: “Unable to access jarfile webapp-runner-7.0.40.0.jar”
[英]Java Spring MVC on Heroku Error: Unable to access jarfile target/dependency/webapp-runner.jar
我使用 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,不知道! 在本地主機上一切正常。
我的 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
簡介:
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 出於某種原因,不使用文件 settings.xml。 當我將此文件的內容傳輸到 pom.xml 並刪除它時,一切正常。
確保您的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>
有關更多信息,請參閱使用 Webapp Runner 部署基於 Tomcat 的 Java Web 應用程序。
對我來說 1) 我在嘗試設置 jhipster upp 以通過 git 而不是通過 jarfile 部署時遇到了它。 我有它是因為 Node.js buildpack 在 java 之前啟動,所以我被迫使用heroku:buildpacks add --index 2 heroku/nodejs
和 heroku:buildpacks add --index 1 heroku/java` 但是即使發生這種變化,我仍然有同樣的錯誤。 2)然后我意識到我在 pom,xml 中有 jar 包裝,而不是所需的 war 包裝。 將此值更改為 pom.xml 對我有幫助。
請參閱我的答案, 找到 webrunner 所在的文件夾,供您的 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.