javac: invalid target release: 1.8

JavaNetbeansJavafxRuntime Error

Java Problem Overview


I recently downloaded JDK 1.8.0.0_06 that comes bundled with NetBeans. I then got to find out that my JavaFx project, that I have been developing in Java 1.7 won't compile in Java 1.8, and so I stepped down my JDK to 1.7. Still I can't get it to work/ compile. I get this error:

javac: invalid target release: 1.8
Usage: javac <options> <source files>

I'm really stuck and would greatly appreciate any help.

Java Solutions


Solution 1 - Java

For IntelliJ14 you may have to change the bytecode version w.r.t. the JDK you are using (in the global settings):

enter image description here

Solution 2 - Java

if you are going to step down, then change your project's source to 1.7 as well,

right click on your Project -> Properties -> Sources window 

and set 1.7 here

note: however I would suggest you to figure out why it doesn't work on 1.8

Solution 3 - Java

  1. Download JDK 8.

  2. Edit your env var for JAVA_HOME to point to the new installed JDK 1.8: R-click on My Computer -> Properties -> Advanced System Settings -> Environment Variables find JAVA_HOME on the list and set it's value to something like that:

     C:\Program Files\Java\jdk1.8.0_31
    
  3. Find the old version and edit it in PATH variable aswell.

  4. Probably you will need to restart the system.

Should be done.

Solution 4 - Java

If this error occurs when running a Gradle (or Maven) task, you need to modify that build tool configuration to point to your installation of Java JDK 1.8 following this route:

File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle

There you check the Linked Gradle project is the one you are working on and select the Gradle JVM (You missed this when you imported the gradle project into IntelliJ)

enter image description here

Remember when importing a Gradle (or Maven) project to set the target JVM correctly here: enter image description here

Solution 5 - Java

Your javac is not pointing to correct java.

Check where your javac is pointing using following command -

update-alternatives --config javac

If it is not pointed to the javac you want to compile with, point it to "/JAVA8_HOME/bin/javac", or which ever java you want to compile with.

Solution 6 - Java

Most of the time, these type of issues happen due to incorrect java version. Make sure your PATH and JAVA_HOME variables are pointing to the correct version.

Solution 7 - Java

Maven setting:

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

Solution 8 - Java

None of the previous solutions worked for me.

I solved it by editing .idea/compiler.xml There were "extra" (1) and (2) copies of the bad module with different targets. I deleted the extraneous entried and changed the targets in the section to 1.8 and it worked.

Solution 9 - Java

For IntelliJ IDEA Ultimate latest version as of 18th Dec 2017, if the above suggestions don't work, then please try the following: Right Click on the project and navigate to "Open Module Settings". Open it, then change the "Language Level" from the dropdown.

Solution 10 - Java

> if you are going to step down, then change your project's source to > 1.7 as well, > > right click on your Project -> Properties -> Sources window and set > 1.7 here" Jigar Joshi

Also go to the build-impl.xml and look for the property excludeFromCopy="${copylibs.excludes}" and delete this property on my code was at line 827 but I`ve seen it on other lines

for me was taking a code from MAC OS java 1.8 to WIN XP java 1.7

Solution 11 - Java

Alternatively, I checked the pom.xml and changed

<java.version>1.8</java.version>

to

<java.version>1.7</java.version>

Solution 12 - Java

I got the same issue with netbeans, but mvn build is OK in cmd window. For me the issue resolved after changing netbeans' JDK (in netbeans.conf as below),

> netbeans_jdkhome="C:\Program Files\Java\jdk1.8.0_91"


Edit: Seems it's mentioned here: [netbeans bug 236364][1]

[1]: https://netbeans.org/bugzilla/show_bug.cgi?id=236364 "netbeans bug 236364"

Solution 13 - Java

Just do this. Then invalidate IntelliJ caches (File -> Invalidate Caches)

Solution 14 - Java

I got the same issue in IntelliJ IDEA Community with Maven and I had to reimport the project by right-clicking the project in the Project tab -> Maven -> Reimport

Solution 15 - Java

I've simply tricked the build system and put Java 8 path into Java 7 section of my Maven's toolchains.xml:

  <toolchain>
    <type>jdk</type>
    <provides>
      <version>1.7.0_80</version>
      <vendor>sun</vendor>
    </provides>
    <configuration>
      <!--jdkHome>C:\Program Files\java\jdk1.7.0_80</jdkHome-->
      <jdkHome>C:\Program Files\java\jdk1.8.0_281</jdkHome>
    </configuration>
  </toolchain>

Solution 16 - Java

Installing a newer release of IDEA Community (2018.3 instead of 2017.x) was solved my issue with same error but java version:11. Reimport hadn't worked for me. But it worth a try.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionProgram-Me-RevView Question on Stackoverflow
Solution 1 - JavavikasingView Answer on Stackoverflow
Solution 2 - JavajmjView Answer on Stackoverflow
Solution 3 - JavathorinkorView Answer on Stackoverflow
Solution 4 - JavajuliangonzalezView Answer on Stackoverflow
Solution 5 - JavaPiyush JajooView Answer on Stackoverflow
Solution 6 - JavajprismView Answer on Stackoverflow
Solution 7 - Javait-webworkView Answer on Stackoverflow
Solution 8 - JavaBill MasekView Answer on Stackoverflow
Solution 9 - JavaAllTooSirView Answer on Stackoverflow
Solution 10 - JavaJAG NUNEZView Answer on Stackoverflow
Solution 11 - JavananospeckView Answer on Stackoverflow
Solution 12 - JavaLeonView Answer on Stackoverflow
Solution 13 - Javauser3399000View Answer on Stackoverflow
Solution 14 - JavaCsa77View Answer on Stackoverflow
Solution 15 - JavaSplashView Answer on Stackoverflow
Solution 16 - JavaLaszlo LugosiView Answer on Stackoverflow