By default, Java apps deployed on Heroku will be running under JDK 1.8, as you can see when deploying an app via Heroku CLI:

heroku deploy java 1.8

To change this default Java version, you have to create the system.properties file under the project’s root directory, with the following content:

java.runtime.version=<jdk_version>

For example, to use JDK 15:

java.runtime.version=15

As of October 2021, Heroku supports Java versions 1.7, 1.8, 11, 13, 15, 16 and 17.

Then, if you deploy via Git push using Heroku CLI, you need to run the following commands to redeploy the app:

git add .

git commit –m “use java version 15”

git push heroku master

Then you should see it is installing JDK 15 for compiling and building the app:

heroku deploy java 15

Now your app is running under the JDK version you specified.



To see the steps in action, watch this video:

 

Other Heroku Tutorials:

 


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.