Updating Existing Java Apps to Use Java 7

Last Updated: 20 March 2014

java jdk openjdk 7

Table of Contents

By default, Java apps run on OpenJDK 6. However, it’s possible to run on newer versions of the JVM. Follow the instructions below to use OpenJDK 7.

If you have questions about Java on Heroku, consider discussing them in the Java on Heroku forums.

Prerequisites

Add system.properties to your app

Create a file in the base directory of your app called system.properties.

Add the property, java.runtime.version=1.7.

Note: Currently, supported versions are 1.6, 1.7, and 1.8. The default is 1.6.

Commit system.properties

$ git add system.properties

$ git commit -m "Adding Java 7 support"

Update your PATH

$ APP_PATH=`heroku config:get PATH`
$ heroku config:set PATH=/app/.jdk/bin:$APP_PATH
Setting config vars and restarting quiet-escarpment-6377... done, v9
PATH: /app/.jdk/bin:/usr/local/bin:/usr/bin:/bin

Push your app

$ git push heroku master

You should see Installing OpenJDK 1.7 in your build output, e.g.

-----> Heroku receiving push
-----> Java app detected
-----> Installing OpenJDK 1.7...done