Table of Contents [expand]
Last updated February 26, 2026
The Java buildpack builds and deploys Maven-based Java applications on Heroku.
Activation
The Java buildpack applies to applications that contain a pom.xml file.
Build Behavior
We recommend using the Maven Wrapper to lock your project to a specific Maven version. If your repository contains an mvnw script and a .mvn/wrapper/maven-wrapper.properties file, the buildpack uses it automatically. If no wrapper is present, the buildpack falls back to its own Maven installation. You can specify which Maven version to use in that case.
The buildpack runs the following default build command:
./mvnw -B -DskipTests clean dependency:list install
The Maven repository is cached between builds to improve performance.
Environment Variables
The following environment variables are set on the dyno at boot time:
PORT: the HTTP port your web process binds toJAVA_HOME: the JDK install directoryLD_LIBRARY_PATH: the JDK shared libraries directoryJDBC_DATABASE_URL: if aDATABASE_URLvariable is present, this variable contains the converted JDBC form. See Connecting to Relational Databases on Heroku with Java for details.JAVA_TOOL_OPTIONS: default JVM options based on dyno size
JAVA_TOOL_OPTIONS
JAVA_TOOL_OPTIONS is a standard JVM mechanism to set options in environments where the command line can’t be accessed or modified. Heroku sets this variable with default JVM options based on dyno size. Since Java automatically picks it up, you don’t need to include it in your Procfile command.
-Dfile.encoding=UTF-8 is always included in the defaults.
JAVA_TOOL_OPTIONS isn’t set for heroku run dynos to avoid interfering with processes that rely on clean standard output, such as MCP servers using the stdio transport.
You can override individual settings in your Procfile command. For example, to increase the maximum heap size:
web: java -Xmx512m -jar target/myapp.jar
You can also set your own JAVA_TOOL_OPTIONS config var. Your values are appended to the defaults and take precedence. Options you don’t override remain in effect.
Adjusting Environment for a Dyno Size
When you select a new dyno type, JVM flags are automatically added to JAVA_TOOL_OPTIONS.
Cedar
Cedar-generation dynos have JAVA_TOOL_OPTIONS set to the following per dyno size:
| Plan | JAVA_TOOL_OPTIONS |
|---|---|
| Eco | -Xmx300m -Xss512k -XX:CICompilerCount=2 |
| Basic | -Xmx300m -Xss512k -XX:CICompilerCount=2 |
| Standard-1X | -Xmx300m -Xss512k -XX:CICompilerCount=2 |
| Standard-2X | -Xmx671m -XX:CICompilerCount=2 |
| Private/Shield-S | -Xmx671m -XX:CICompilerCount=2 |
| Performance/Private/Shield-M | -XX:MaxRAMPercentage=80.0 |
| Performance/Private/Shield-L | -XX:MaxRAMPercentage=80.0 |
| Performance/Private/Shield-L-RAM | -XX:MaxRAMPercentage=80.0 |
| Performance/Private/Shield-XL | -XX:MaxRAMPercentage=80.0 |
| Performance/Private/Shield-2XL | -XX:MaxRAMPercentage=80.0 |
Fir
All Fir-generation dynos have JAVA_TOOL_OPTIONS set to -XX:MaxRAMPercentage=80.0.