Deploying a Vaadin Application to Heroku
This tutorial shows you how to deploy a Vaadin application to Heroku cloud platform. Heroku has a free-tier offering that can be used for non-commercial applications. You can find details about their free offerings on Heroku website.
Note | Heroku account required
To complete this tutorial, you need a Heroku account.
You can sign up at https://signup.heroku.com/.
|
Step 1: Install and Setup Heroku CLI
To begin, download and install the Heroku CLI.
Once installed, login to your account from a terminal window using the following command:
heroku login
Next, install Heroku’s Java plugin by issuing the following command:
heroku plugins:install java
Step 2: Download a Starter App
Download a minimal Vaadin project and unpack the downloaded zip into a folder on your computer.
Step 3: Add Java 11 Support
The starter project is on Java 11, whereas Heroku expects Java 8 projects by default. To ensure that Heroku would run a Java 11 environment, create a system.properties file under the project’s root directory with the following content:
java.runtime.version=11
Step 4: Create a Production Build
Open the project directory from a terminal window, and enter the following command to generate a JAR file of your application:
mvn package -Pproduction
Step 5: Initialize a Heroku Application
From a terminal window, enter the following command to initialize a Heroku application:
heroku create --no-remote
This command will create an application with a randomly generated name.
Take a note of the generated application name that will appear in the logs.
For example, in the following screenshot, the generated application name is blooming-beach-34155
.
Step 6: Deploy the Application
To deploy the application, run the following command from a terminal at your project’s root directory (replacing 'blooming-beach-34155' in the command with your application name noted in the previous step):
heroku deploy:jar target/myapp-1.0-SNAPSHOT.jar --app blooming-beach-34155
When the deployment completes, the application URL will be displayed in the logs.