简体   繁体   中英

Java web app on Heroku: Unable to access jarfile

I'm trying to deploy my Java Spring Boot web application to Heroku.

To launch it locally I run:

mvn install

and then

java $JAVA_OPTS -jar target/*.war

So for Heroku I've created the Procfile: web: java $JAVA_OPTS -jar target/*.war

I use Heroku Github integration and the application is deployed to Heroku from Github. So I just push it there.

But the application doesn't launch.

heroku logs --app myapp gives me:

2015-09-09T21:53:25.581128+00:00 heroku[web.1]: Starting process with command `java $JAVA_OPTS -jar target/*.war`
2015-09-09T21:53:27.110820+00:00 app[web.1]: Error: Unable to access jarfile target/*.war`

heroku run bash --app myapp with ls -a doesn't show target directory.

I think Heroku doesn't build the app. But what am I doing wrong? Thanks in advance for you advices!

Instead of mvn install do mvn package to know the difference check http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

Deploying a WAR file with the Heroku Maven plugin allows you to integrate the deployment process with your existing Maven process. The Heroku plugin uses the artifacts generate by your mvn package phase, and builds them into a Slug file that is uploaded to the Heroku servers.

In this way, the Heroku Maven plugin avoids the overhead of recompiling your project remotely. This is often the preferred approach when deploying from a CI server, which may already have built your WAR file and tested it.

Source: https://devcenter.heroku.com/articles/war-deployment#deployment-with-the-heroku-maven-plugin

Regarding deploying Spring Boot, there are some steps to be taken:

  • Configure port

    web: java -Dserver.port=$PORT -jar target/demo-0.0.1-SNAPSHOT.jar

  • Specify JDK, default is 1.8 (No need to change if 1.8 is specified in Maven)

Check http://docs.spring.io/spring-boot/docs/current/reference/html/cloud-deployment-heroku.html

To execute Procfile use heroku local

I found the cause of the error. Here is a part of build log:

-----> Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
       Detected buildpacks: Node.js, Java
       See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
-----> Node.js app detected
-----> Creating runtime environment

According to Heroku build order the application was considered as NodeJS one. So the solution was to set java build pack:

heroku buildpacks:set https://github.com/heroku/heroku-buildpack-java

And then push any change to application to make it rebuilt.

  1. Packaging part in pom.xml should be always war, not jar
  2. Putting java buildpack with priority 1 and nodejs with priority 2 also helped

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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