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
If you have questions about Java on Heroku, consider discussing them in the Java on Heroku forums.
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
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: -Xmx384m -Xss512k -XX:+UseCompressedOops
MAVEN_OPTS: -Xmx384m -Xss512k -XX:+UseCompressedOops
PORT: HTTP port to which the web process should bind
DATABASE_URL: URL of the database connection
Adjusting Environment for a Dyno Size
When a new dyno size is selected, the following
JAVA_OPTS updates are recommended:
1X: -Xmx384m -Xss512k
2X: -Xms768m -Xmx768m -Xmn192m
PX: -Xmx4g -Xms4g -Xmn2g
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.
Heroku currently uses OpenJDK to run your application. OpenJDK versions 6 and 7 are available using a
system.properties file. OpenJDK 8 with Lambdas is also available as an early preview. See the Java Tutorials for more information.
web process type is defined for Java applications. See one of the Java tutorials for information on setting up your
The JDK that your app uses will be included in the slug, which will affect your slug size.
A Postgres database is automatically provisioned for Java applications. This populates the DATABASE_URL environment variable.