Skip Navigation
Show nav
Heroku Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku Architecture
    • Dynos (app containers)
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Command Line
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery
    • Continuous Integration
  • Language Support
    • Node.js
    • Ruby
      • Working with Bundler
      • Rails Support
    • Python
      • Working with Django
      • Background Jobs in Python
    • Java
      • Working with Maven
      • Java Database Operations
      • Working with the Play Framework
      • Working with Spring Boot
      • Java Advanced Topics
    • PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
    • Heroku Redis
    • Apache Kafka on Heroku
    • Other Data Stores
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
    • Compliance
  • Heroku Enterprise
    • Private Spaces
      • Infrastructure Networking
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
    • Single Sign-on (SSO)
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Language Support
  • Java
  • Heroku Java Support

Heroku Java Support

English — 日本語に切り替える

Last updated January 22, 2021

Table of Contents

  • Activation
  • Build behavior
  • Environment
  • Supported Java versions
  • Add-ons
  • Further Reading

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:

  • Getting Started with Java on Heroku
  • Java Tutorials

Activation

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

Environment

The following environment variables will be set in dyno at boot-time:

  • PORT: HTTP port to which the web process should bind
  • JAVA_HOME: The location of the JDK install directory
  • LD_LIBRARY_PATH: With the location of the JDK shared libraries
  • JDBC_DATABASE_URL: If a DATABASE_URL variable is present, this will be populated with the converted form. See Connecting to Relational Databases on Heroku with Java for more information.
  • JAVA_TOOL_OPTIONS: Default Java options based on dyno size
  • JAVA_OPTS: Default Java options based on dyno size (identical to JAVA_TOOL_OPTIONS)

About JAVA_TOOL_OPTIONS

JAVA_TOOL_OPTIONS is directly supported by Java and intended to augment a command line in environments where the command-line cannot be accessed or modified. Heroku uses this to set default Java options based on dyno size. Since it is automatically picked up by Java, you do not need to include it in your Procfile command.

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. Setting your own will cause its value to be appended to Heroku’s defaults and take precedence. Individual options not overridden in the Procfile command or custom JAVA_TOOL_OPTIONS will still be in effect.

When a Java process is started on your dyno, the following Java options will be added to JAVA_TOOL_OPTIONS and automatically picked up by Java:

  • -Dfile.encoding=UTF-8
  • -XX:+UseContainerSupport (for Java 11 and higher)

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: -Xmx300m -Xss512k -XX:CICompilerCount=2
  • standard-2x: -Xmx671m -XX:CICompilerCount=2
  • performance-m: -Xmx2g
  • performance-l: -Xmx12g

For Private Space dynos, the values are:

  • private-s: -Xmx671m -XX:CICompilerCount=2
  • private-m: -Xmx2g
  • private-l: -Xmx12g

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 versions 15, 13, 11, and 7 are 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 default versions are:

  • Java 7 - 1.7.0_292
  • Java 8 - 1.8.0_282
  • Java 11 - 11.0.10
  • Java 13 - 13.0.6
  • Java 15 - 15.0.2

The JDK that your app uses will be included in the slug, which will affect your slug size.

Specifying a Java version

When a JDK version reaches EOL security patches may no longer be available. We highly recommend running on a version of the JDK that is actively supported by the community.

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:

java.runtime.version=11

Accepted major version values are 1.7, 1.8, 11, 13 and 15. Because the default is 1.8, you don’t need this file if you would like to use Java 8.

You can also pin your JDK update version by using a value such as this:

java.runtime.version=1.8.0_202

However, we encourage you to use the more general 1.8 format, which will automatically install any security updates.

Using the Zulu JDK

In addition to the standard JDK, Heroku provides support for the Azul® Zulu® JDK. Zulu is a 100% open source certified build of OpenJDK that is fully compliant with the Java SE standard.

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:

java.runtime.version=zulu-1.8.0_212

For more information on the Zulu JDK, see the official Azul 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 system.properties file.

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:

maven.version=3.6.2

If this property is defined, the mvnw script will be ignored.

Accepted values for maven.version are:

  • 3.2.5
  • 3.3.9
  • 3.5.4
  • 3.6.2

The default, if you do not specify a version, is 3.6.2. 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

The Java buildpack will automatically detect the use of the Spring Boot and Thorntail web frameworks. For Spring Boot, it will create a web process type with the following command:

java -Dserver.port=$PORT $JAVA_OPTS -jar target/*.jar

For Thorntail, 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 Procfile.

Add-ons

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

Further Reading

  • Warming Up a Java Process
  • Running Database Migrations for Java Apps
  • Reducing the Slug Size of Java Applications

Keep reading

  • Java

Feedback

Log in to submit feedback.

Setting the HTTP Port for Java Applications Introduction to Heroku for Java Developers

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Podcasts
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing

Subscribe to our monthly newsletter

Your email address:

  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Heroku Podcasts
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Facebook
  • Instagram
  • Github
  • LinkedIn
  • YouTube
Heroku is acompany

 © Salesforce.com

  • heroku.com
  • Terms of Service
  • Privacy
  • Cookies