Heroku Java Support

Last Updated: 19 June 2015

java maven

Table of Contents

The Heroku Cedar stack is capable of running a variety of types of Java applications.

This document describes the general behavior of the Heroku Cedar stack 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:

You can also find template applications that can be cloned directly into your Heroku account at java.heroku.com


The default build system for Java application on Heroku is Maven. Heroku Java support for Maven will be applied to applications that contain a pom.xml.

When a deployed application is recognized as a Java application, Heroku responds with -----> Java app detected.

$ git push heroku master
-----> Java app detected

Build behavior

The following command is run to build your app:

$ mvn -B -DskipTests=true clean install

The maven repo is cached between builds to improve performance.


The following config vars will be set at first push:

  • JAVA_OPTS: -XX:+UseCompressedOops
  • PORT: HTTP port to which the web process should bind
  • DATABASE_URL: URL of the database connection

Resizing dynos automatically changes Java memory settings. The JAVA_OPTS config var can be manually adjusted to override these defaults.

When a Java process is started on your dyno, the follow Java options will automatically be picked up:

  • -Dfile.encoding=UTF-8 -Djava.rmi.server.useCodebaseOnly=true

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 JAVA_TOOL_OPTIONS:

  • free, hobby or standard-1x: -Xmx384m -Xss512k
  • standard-2x: -Xmx768m
  • performance: -Xmx4g

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 default. OpenJDK versions 6 and 7 are available. Depending on the major version you select the latest available update of that Java runtime will be used each time you deploy your app.

Current versions are:

  • Java 6 - 1.6.0_27
  • Java 7 - 1.7.0_79
  • Java 8 - 1.8.0_40

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.6, 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.

Specifying a Maven version

You can also specify a Maven version with the system.properties file by setting a maven.version property like this:


Accepted values are 3.0.5, 3.1.1, 3.2.5 and 3.3.1. The default, if you do not specify a version, is 3.3.1. 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

No default web process type is defined for Java applications. See one of the Java tutorials for information on setting up your Procfile.


A Postgres database is automatically provisioned for Java applications. This populates the DATABASE_URL environment variable.