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!
Then you can deploy by running: The sbt-heroku plugin will skip the default sbt-native-packager execution and deploy your JAR directly to Heroku. Other JVM languages have support for deploying executable JAR files on Heroku. For more information see:
an existing Java app that uses Maven as a build tool. The details of Heroku’s Java Support are described in the Heroku Java Support article. Heroku Java support for Maven will be applied to applications that contain a pom.xml file.
The Heroku Java CLI plugin can deploy a pre-built JAR file with very little set up or dependencies. To use it, you must have created a Heroku account and installed the Heroku CLI.
There are several different reasons for the “Java unable to Access Jarfile” issue. Most of them are related to the handling of JAR files on your computer. 1. The latest Java version has not been installed on your computer. 2. The file path set for the Java executable is incorrect and points to the wrong location.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With