Nailgun
Nailgun

Reputation: 4179

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!

Upvotes: 7

Views: 14432

Answers (4)

Changing Packaging from jar to war in the pom.xml worked well for me

Upvotes: 0

Eljah
Eljah

Reputation: 5165

  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

Upvotes: 0

Nailgun
Nailgun

Reputation: 4179

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.

Upvotes: 5

Sully
Sully

Reputation: 14943

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

Upvotes: 8

Related Questions