In this last chapter, you prepare the CRM application for production and deploy it to Heroku. The tutorial uses Heroku because it’s simple and comes with a free tier that does not require a credit card when signing up. The free tier also includes PostgreSQL support.
You can deploy Vaadin applications on any cloud provider
You can deploy Vaadin applications on any cloud provider or hosting service that supports Java.
The project also contains a
This chapter covers:
Vaadin production builds.
Creating a Heroku account.
Installing the Heroku CLI.
Creating and deploying a Heroku app.
pom.xml build includes a
production profile configuration that prepares an optimized build that’s ready for production.
During development, the application has used an in-memory H2 database. It is convenient and works well for a single user. In production, you want to use something more robust and persistent. Heroku’s free tier supports PostgreSQL, so can configure your application to use that.
First, add the PostgreSQL dependency in the production profile of
<profile> <id>production</id> <!-- Omitted --> <dependencies> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> </dependency> </dependencies> </profile>
Next, configure how JPA should handle schema generation.
Add the following two properties to the end of
Use the Heroku CLI to create and deploy your application.
Configure the correct Java version:
echo "java.runtime.version=11" > system.properties
Install the Heroku Java plugin:
heroku plugins:install java
Create a new app. Replace APPNAME with a name of your choice. APPNAME is part of the URL, like https://APPNAME.herokuapp.com, so choose a name that’s unique and easy to remember.
heroku create APPNAME
Create a secret key for your application:
heroku config:set APP_SECRET=$(openssl rand -base64 32)
Enable the PostgreSQL plugin for the newly created app:
heroku addons:create heroku-postgresql -a APPNAME
Deploy the production-optimized JAR file you created in the previous section.
heroku deploy:jar target/fusioncrmtutorial-1.0-SNAPSHOT.jar -a APPNAME
Open the application in your browser.
View the application logs and see if anything goes wrong.
heroku logs --tail
Congratulations, you have now built a full-stack PWA and deployed it to Heroku.
Now that you have a running application, you can use it to experiment further or use it as a foundation for your next idea.
Happy hacking, and ping us @vaadin on Twitter to show off the cool stuff you’ve built!