6

I wanted to deploy my java 7 application to Heroku but I encountered some problems with java version.

I added system.properties file in my project root directory (where src and pom.xml are) with content java.runtime.version=1.7 but still I am getting something like this:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project lets-code: Fatal error compiling: invalid target release: 1.7

so I am a bit confused as to what to do next.

Andna
  • 6,539
  • 13
  • 71
  • 120

4 Answers4

6

The default version of Java on Heroku is Java 6. You need to follow the Guidelines to make your maven project run on newer versions of the JVM (1.7 or 1.8). You already added the system.properties file to your project. However you probably did not updated the PATH as specified and maven tries to build your app using OpenJDK 6 which leads to the invalid target release exception.

Updating the PATH should do the trick.

abronan
  • 3,309
  • 4
  • 29
  • 38
  • 1
    Yes, that was the problem, I was following this tutorial: https://devcenter.heroku.com/articles/getting-started-with-java and there was no information about changing `PATH` – Andna Nov 18 '13 at 09:34
  • 2
    How to do this? – Tareq Jul 08 '20 at 19:11
  • @Tareq Here is a link to a website that explains what to do and even has a video at the bottom showing you how to do it. https://www.codejava.net/heroku/change-java-version-for-apps – Joseph Waweru Mar 25 '22 at 08:59
  • @Joseph Waweru It is not working for me. I am trying to change the version to 17. I followed all your steps but it is still compiling using 1.8 version on Heroku. What can be the problem? – pyfyc Jun 25 '23 at 07:23
5

I used the following guide https://devcenter.heroku.com/articles/customizing-the-jdk :

Specify a JDK version Create a system.properties file if one does not already exist, specify the version, and commit it to git. Supported version are described in the Java Support article. The file’s contents should look something like this:

java.runtime.version=11 Then add the file to Git by running:

git add system.properties git commit -m "JDK 11"

It works for me.

Yauhen
  • 1,145
  • 12
  • 19
1

Most of the answers of the question will be above.but there are lots of new developers who doesn't get above problem solve.For those i am commenting here.

If anyone confusing where to put system.properties file to set java version and maven version, it's suggested to put adjacent with pom.xml file (near pom.xml file or outside src folder)

lama
  • 11
  • 2
1
\Project root folder
│  pom.xml
│  system.properties  // here, same depth of pom.xml
│          
├─src
│  ├─main
│  │  ├─java
│  │  │  │  module-info.java
│  │  │  │  
│  │  │  └─com
│  │  │      └─github
│  │  │          └─graycat27
│  │  │              └─myApp
│  │  │                  │  MyApp.java

This location worked well.

then the build log on Heroku will be...

-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/java
-----> Java app detected
-----> Installing OpenJDK 17... done  // before set sys.prop, the version may JDK8
-----> Installing Maven 3.6.2... done
-----> Executing Maven
       $ mvn -DskipTests clean dependency:list install
graycat27
  • 11
  • 1