Deploying Executable JAR Files
Last updated November 29, 2023
Table of Contents
Many Java and JVM applications are packaged into a self-contained executable JAR file that includes application code, configuration and dependencies. These artifacts are often called “uberjars” or “fat jars”.
This article shows several different techniques for deploying a fat JAR to Heroku.
Using the Heroku Java CLI plugin
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. Then run this command to install the plugin:
$ heroku plugins:install java
Then create an application:
$ heroku create --no-remote
And deploy your JAR file by running this command, replacing the app name (sushi
in this case) with the app name generated by the previous command:
$ heroku deploy:jar target/my-app.jar --app sushi
You can customize the execution of the JAR file by creating a Procfile
or including additional files in the deployment.
Using the Heroku Maven plugin
The Heroku Maven Plugin can be used as described in Deploying Java Applications with the Heroku Maven Plugin, but with the following configuration:
<includeTarget>false</includeTarget>
<includes>
<include>target/my-app-1.0.jar</include>
</includes>
Then configure your process types to execute the JAR by adding some configuration like this:
<processTypes>
<web>java -jar target/my-app-1.0.jar</web>
</processTypes>
You can customize the deployment as described in Deploying Java Applications with the Heroku Maven Plugin.
Deployment with Git
When you deploy your source code to Heroku with git push heroku master
(as described in Deploying with Git), your JAR file will be included in your app’s slug. You only need to define how to run it in the app’s Procfile. For example:
web: java -jar target/myapp.jar
Make sure you add your Procfile
changes to your Git repository.
Deployment with Scala, Clojure and Gradle
Other JVM languages have support for deploying executable JAR files on Heroku. For more information see:
- Gradle: Deploying Gradle Apps on Heroku
- Clojure: Uberjar deployment with Git