Get Started with Java on Heroku
After completing this project, you'll be able to:
- Create a Heroku account.
- Install tools needed to use Heroku.
- Create and deploy a Heroku app.
- Scale your Java app using Heroku tools.
- Modify and improve your Java app.
Heroku is a Platform-as-a-Service (PaaS). It abstracts away the complexity of building and running cloud infrastructure. You can use Heroku to deploy, manage, and scale your apps without the fuss of hardware or virtual machines. In this module, you learn how to get a real Java application running on Heroku in just a few steps.
To deploy an app on Heroku, create a free Heroku account by visiting signup.heroku.com and filling out a few bits of information. You don’t need a credit card for now.
This project requires a local installation of Java 8 or higher on your computer. If you don't already have it, visit the
Java SE Downloads website and select the correct version for your platform. To ensure you have the right version installed, you can run the command
java -version in your command shell and confirm v 8.0 or higher is installed.
Next, install the Heroku Command Line Interface (CLI). You use the CLI to manage and scale your applications, provision add-ons, view the logs of your application as it runs on Heroku, and help run your application locally.
Once installed, you can use the
git commands from your command shell. Type
heroku login and use the email address and password you used when creating your Heroku account to authenticate.
Authentication is required to allow both the
git commands to work.
Note that if you’re behind a firewall that requires use of a proxy to connect with external HTTP/HTTPS services,
you can set the HTTP_PROXY or HTTPS_PROXY environment variables in your local development environment before running the
Next, you prepare a simple application for deployment and then run it on Heroku. To begin, clone the application repository so that you have a local version of the code by executing the following commands in your local command shell or terminal:
mkdir heroku-java cd heroku-java git clone https://github.com/heroku/java-getting-started.git cd java-getting-started
You now have a functioning Git repository that contains a simple application as well as a
pom.xml file that is used by Java’s dependency manager, Maven.
Now you deploy your repository to a Heroku app. Each Heroku app receives source code from a Git repository, like the one you created, and compiles it to run on the platform. Create a Heroku app by running
When you create a Heroku app, a Git remote (called “
heroku”) is also created and associated with your local git repository. Heroku generates a random name (in this case
shielded-peak-44334) for your app. You can also pass a
parameter to specify your own app name.
Now deploy your code by pushing to the Git remote repository associated with your Heroku app.
git push heroku master
If deployed correctly, you should see output similar to this:
The application is now deployed. Ensure that at least one instance of the app is running.
heroku ps:scale web=1
Now visit the app at the URL generated by its app name. As a handy shortcut, you can open the website using the CLI.
You see the Heroku template app in the browser. Congratulations! You’re running your first web application on the Heroku cloud.
Click Verify Step to proceed to the next step in the project.