Program-Me-Rev
Program-Me-Rev

Reputation: 6624

javac: invalid target release: 1.8

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.

Upvotes: 91

Views: 181568

Answers (16)

Splash
Splash

Reputation: 126

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>

Upvotes: 0

Laszlo Lugosi
Laszlo Lugosi

Reputation: 3829

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.

Upvotes: -1

user3399000
user3399000

Reputation: 387

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

Upvotes: 1

Csa77
Csa77

Reputation: 697

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

Upvotes: 0

AllTooSir
AllTooSir

Reputation: 49402

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.

Upvotes: 2

Leon
Leon

Reputation: 3244

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

Upvotes: 1

Bill Masek
Bill Masek

Reputation: 39

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.

Upvotes: 3

jprism
jprism

Reputation: 3494

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.

Upvotes: 9

nanospeck
nanospeck

Reputation: 3548

Alternatively, I checked the pom.xml and changed

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

to

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

Upvotes: 1

thorinkor
thorinkor

Reputation: 966

  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.

Upvotes: 27

JAG NUNEZ
JAG NUNEZ

Reputation: 11

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

Upvotes: 1

juliangonzalez
juliangonzalez

Reputation: 4381

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

Upvotes: 25

it-webwork
it-webwork

Reputation: 51

Maven setting:

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

Upvotes: 5

vikasing
vikasing

Reputation: 11772

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

Upvotes: 68

Piyush Jajoo
Piyush Jajoo

Reputation: 1093

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.

Upvotes: 14

Jigar Joshi
Jigar Joshi

Reputation: 240948

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

Upvotes: 35

Related Questions