Heroku Java Support
Last updated 30 May 2017
Heroku is capable of running Java applications across a variety of Java implementations and includes support for framework-specific workflows.
This document describes the general behavior of Heroku as it relates to the recognition and execution of Java applications. General Java support on Heroku refers to the support for all frameworks except for Play. You can read about Play framework support in the Play framework support reference.
For framework specific tutorials visit:
The default build system for Java application on Heroku is Maven. Heroku Java support for Maven will be applied to applications that contain a
When a deployed application is recognized as a Java application, Heroku responds with
-----> Java app detected.
$ git push heroku master -----> Java app detected
The following command is run to build your app:
$ mvn -B -DskipTests clean dependency:list install
However, if Heroku detects a
mvnw script in your application’s repository, it will run this instead of the default Maven installation. You can override this behavior by explicitly setting a Maven version.
The maven repo is cached between builds to improve performance.
The following config vars will be set at first push:
PORT: HTTP port to which the web process should bind
DATABASE_URL: URL of the database connection
When a Java process is started on your dyno, the follow Java options will automatically be picked up:
These options are configured as part of the environment variable
JAVA_TOOL_OPTIONS, which is intended to augment a command line in environments where the command-line cannot be accessed or modified. If you need to override these settings you can either define your preferred options in the
Procfile command (which will take precedence), or set your own
JAVA_TOOL_OPTIONS config var.
Adjusting Environment for a Dyno Size
When a new dyno type is selected, the following settings are automatically added to
- free, hobby or standard-1x:
For Private Space dynos, the values are:
Monitoring Resource Usage
Additional JVM flags can be used to monitor resource usage in a dyno. The following flags are recommended for monitoring resource usage:
-XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+UseConcMarkSweepGC
See the troubleshooting article for more information about tuning a JVM process.
Supported Java versions
Heroku currently uses OpenJDK 8 to run your application by default. OpenJDK version 7 is also available. Depending on the major version you select the latest available update of that JDK will be used each time you deploy your app.
Current versions are:
- Java 7 -
- Java 8 -
The JDK that your app uses will be included in the slug, which will affect your slug size.
Specifying a Java version
You can specify a Java version by adding a file called
system.properties to your application.
Set a property
java.runtime.version in the file:
Accepted values are 1.7 and 1.8. The default is 1.8 so if you’d like to use Java 8 you don’t need this file at all.
You can also pin your JDK update version by using a value such as this:
This will force the buildpack to install the specific version of the JDK. The supported update versions include:
However, we strongly encourage you to use the more general
1.8 format, which will automatically install any security updates.
Using the Zulu JDK
To use Zulu with your app, create a
system.properties file in the root directory of your application with the following contents and add it to Git:
The official buildpacks will install version 8u102 of the Zulu on the next deployment. You can confirm this by running the following command:
$ heroku run java -version Running java -version on ⬢ sushi... up, run.5064 (Free) openjdk version "1.8.0_112" OpenJDK Runtime Environment (Zulu 18.104.22.168-linux64) (build 1.8.0_112-b16) OpenJDK 64-Bit Server VM (Zulu 22.214.171.124-linux64) (build 25.112-b16, mixed mode)
Available versions include the following:
For more information on the Zulu JDK, see the official Azul documentation.
Early Access to JDK 9
Heroku provides early access to prerelease versions of JDK 9. Create a
system.properties file in the root directory of your repository with the following contents:
Add the file to Git, and JDK 9 will be installed when you redeploy. The list of prerelease versions includes:
Be aware that JDK 9 may not be production ready, and it should be used with caution until a general availability release has been announced.
For more information on JDK 9, see the official OpenJDK documentation.
Upgrading your Java version
All Java apps will be automatically upgraded to the latest available JDK version when and only when they are deployed. They are not upgraded if the app is not re-deployed or if a specific version is configured in the
Specifying a Maven version
Heroku provides support for Maven Wrapper, which is the recommend mechanism for defining a Maven version. If Heroku detects a
mvnw file in the root directory of your repository, it will use this script to launch the Maven process.
You can also specify a Maven version with the
system.properties file by setting a
maven.version property like this:
If this property is defined, the
mvnw script will be ignored.
Accepted values for
maven.version are 3.0.5, 3.1.1, 3.2.5 and 3.3.9. The default, if you do not specify a version, is 3.3.9. You will not be upgraded to a newer version automatically. If you are currently using 3.0.5 and want to upgrade to the latest version, then you must create the
system.properties file and specify the version.
Default web process type
java -Dserver.port=$PORT $JAVA_OPTS -jar target/*.jar
For Wildfly Swarm, the buildpack will use this command for the default
web process type:
java -Dswarm.http.port=$PORT $JAVA_OPTS -jar target/*.jar
You can override these defaults or define a custom process type using a
Procfile. The appropriate command depends on your app and the frameworks in use. See one of the Java tutorials for information on setting up your
A Postgres database is automatically provisioned for Java applications that have a dependency on the Postgres JDBC driver or pgjdbc-ng driver in their
pom.xml. This populates the
DATABASE_URL environment variable.
If you do not need or do not want the Postgres add-on, you can remove it by running:
$ heroku addons:destroy DATABASE --app sushi