Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't Eclipse switch the compiler to Java 8?

Tags:

java

eclipse

I checked out a Java project from SVN in Eclipse and realized that it requires Java 8 because it uses lambdas etc. I installed the Eclipse addon for Java 8 and restarted Eclipse and and have the project set up like so:

New Java Project

I noticed that near the bottom, it says that the default compiler compliance is 1.7, so I went into org.eclipse.jdt.core.prefs and set the compiler compliance variable to 1.8, as per this answer. However, in Project -> Preferences -> Java Compiler, it still shows up as:

Eclipse please

I have set the JRE in Project -> Java Build Path:

jre8

Yet the compiler refuses to compile lambda expressions - I get an error that looks like what I would get if I went ahead and typed it into Java 7.

This is the version of Eclipse I'm using:

Version: Kepler Service Release 1
Build id: 20130919-0819

Is the only way to solve this to install a fresh version of Eclipse or am I missing something in the configuration?

like image 867
itdoesntwork Avatar asked Jul 25 '14 04:07

itdoesntwork


People also ask

How do I change my Java from 11 to 8 in Eclipse?

Click on the Window tab in Eclipse, go to Preferences and when that window comes up, go to Java → Installed JREs → Execution Environment and choose JavaSE-1.5. You then have to go to Compiler and set the Compiler compliance level.

How do I change the compiler version in Eclipse?

To change the compiler version in eclipse you need to go to Windows > Preferences > Java > Compiler. There you will see Compiler Compilation Level where in drop-down you will see all compiler version available in system.

Does Eclipse work with Java 8?

A Java 8 or newer JRE/JDK is required to run all Eclipse 2019-09 packages based on Eclipse 4.14, as well as the Installer.


3 Answers

Two things:

First, JRE is not the same as the JDK. If you do have the JDK, you need to configure eclipse to point to that in your settings.

Second, in your screenshot above, your compiler compliance level is set to 1.7. This will treat all your code as if it's using Java 1.7. Change this to 1.8 to fix your error.

You will need to have Eclipse Luna in order to get support for Java 8, but you can add it to Kepler SR2 if you want. I'd try with Luna and the above suggestions before you go any further. See this reference.

Once you get Luna, your JAVA_HOME variable should be enough to get Eclipse to recognize JDK 8. If you want to specify an additional JDK, you can add a new Java System Library by going to:

Project -> Properties -> Java Build Path -> Libraries -> Add Library -> Java System Library 

and navigating to a valid location for the JDK 8.

You can download your platform's JDK 8 here

like image 131
Ryan J Avatar answered Sep 30 '22 10:09

Ryan J


It cause eclipse kepler SR1 does not support new Java™ 8 language enhancements like lambda expression.

From information here: http://www.eclipse.org/downloads/java8/
I think you should use kepler SR2 with support plugin, or change to Eclipse Luna.


Updated link 16/09/2016: https://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler

like image 38
teddy Avatar answered Sep 30 '22 09:09

teddy


I had the same problem even though I had:

  • a freshly downloaded JDK 1.8.0

  • JAVA_HOME is set

  • java -version on command line reports 1.8

  • Java in control panel is set to 1.8

  • downloaded Eclipse Mars

Eclipse only let me choose a compiler compliance level op to 1.7 in the compiler preferences, even though my installed JRE is 1.8.0. I also couldn't see a 1.8 in the Execution Environments underneath Installed JREs, only a JavaSE-1.7 (which I haven't even got installed!). When I clicked on that, it shows "jdk1.8.0" as a compatible JRE, so I selected that, but still no change.

Then I unzipped Eclipse Mars into a brand new directory, created a new project, and now I can select 1.8, hurrah! That greatly reduced the "Duplicate methods named spliterator..." errors I was getting when compiling my code under Java 1.8, however, there is still one left:

Duplicate default methods named spliterator with the parameters () and () are inherited from the types List and Set.

However, that's likely because I'm extending AbstractList and implementing Set, so I've fixed that for now by removing the implements Set because it doesn't really add anything in my case (other than signifying that my collection has only unique elements)

like image 32
Thomas R Avatar answered Sep 30 '22 10:09

Thomas R