34

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?

Lii
  • 11,553
  • 8
  • 64
  • 88
itdoesntwork
  • 4,666
  • 3
  • 25
  • 38
  • I do. Is there anywhere I should be setting that? – itdoesntwork Jul 25 '14 at 04:07
  • 1
    It sounds like you need a newer version of Eclipse that supports Java 8. Your second screenshot (Java Compiler preferences) needs to be set to use 1.8 compliance, and earlier versions do not support this. – Krease Jul 25 '14 at 04:29

11 Answers11

44

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

Ryan J
  • 8,275
  • 3
  • 25
  • 28
  • 5
    I should have included that in my question - the UI doesn't let me change that setting. The dropdown menu ends at 1.7. I'm checking out JDK settings right now, though, because I do have JDK 8 installed. – itdoesntwork Jul 25 '14 at 04:13
  • What is your JAVA_HOME environment variable set to? – Ryan J Jul 25 '14 at 04:17
  • `C:\Program Files\Java\jdk1.6.0_35`. I changed it to `...\jdk1.8.0_11` and restarted eclipse but nothing has changed. Regarding the JDK, I changed the system library from jre8 to jdk1.8.0_11 but that changed nothing either. – itdoesntwork Jul 25 '14 at 04:22
  • 4
    See latest update. You're not using a version of Eclipse that supports Java 8, which is why you can't change your compliance level. Try with a later version of Eclipse. – Ryan J Jul 25 '14 at 04:25
  • 2
    I have Kepler SR2 (Spring Tool Suite), but it will not let me set the compiler compliance to 1.8 (I'm running STS with JDK 1.8 and the project classpath has the 1.8 runtime). The answer on http://stackoverflow.com/questions/21955207/version-1-8-of-project-facet-java-does-not-exist shows how to add the required plugins. After installing those, I was able to set the compiler compliance to 1.8 – djb May 27 '15 at 18:56
  • 1
    The cited "this reference" link http://www.eclipse.org/downloads/java8/ returns a 404. I did find https://wiki.eclipse.org/JDT_Core/Java8 – djb May 27 '15 at 18:56
  • The key phrase for me above was "You will need to have Eclipse Luna in order to get support for Java 8" – Doo Dah Apr 06 '17 at 15:23
6

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

teddy
  • 534
  • 5
  • 13
  • [This article](http://waynebeaton.wordpress.com/2014/03/26/add-java-8-support-to-eclipse-kepler/) says that Java 8 does indeed work on Eclipse Kepler SR1, though, and links the same installation page that I used. However, I'll still download Luna and see if it works. – itdoesntwork Jul 25 '14 at 04:25
  • I've not tried install this on Kepler SR1. But follow the article, you can change java to 1.8 inside GUI once plugin installed successfully. – teddy Jul 25 '14 at 04:40
  • 1
    The cited link http://www.eclipse.org/downloads/java8/ returns a 404. I did find https://wiki.eclipse.org/JDT_Core/Java8 – djb May 27 '15 at 18:56
4

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)

Thomas R
  • 49
  • 2
  • I had the same problem and "symptoms", no idea why, but i re-downloaded Eclipse and I could import my old workspace and it still worked. Hooray! – JonatanSJ Sep 17 '15 at 07:58
2

Old question, but posting the answer incase it helps someone. Already build path was configured to use JDK 1.2.81 However, build was failing with the error below:

 lambda expressions are not supported in -source 1.5
[ERROR]   (use -source 8 or higher to enable lambda expressions)

In the latest Eclipse (Photon), adding the below entry to pom.xml worked.

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
  </properties>
ForeverLearner
  • 1,901
  • 2
  • 28
  • 51
1

First of all you should get JdK 8.

if you have Jdk installed.

you should set its path using cmd prompt or system variables.

sometimes it can happen that the path is not set due to which eclipse is unable to get the properties for jdk.

Installing latest ecipse luna can solve your problem.

i have indigo and luna. i can set 1.8 in luna but 1.7 in indigo.Eclipse luna

You can check the eclipse site. it says that the eclipse luna was certainly to associate the properties for jdk 8.

Deepanshu J bedi
  • 1,530
  • 1
  • 11
  • 23
1

You must install the JDT/Eclipse Java 8 Support For Kepler. https://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler

tranan
  • 11
  • 2
1

I had the similar problem with eclipse kepler.I have followed these steps to resolve it

  • Go to Help in Eclipse and Open Eclipse Market Place option.
  • Search for jdk 1.8 for kepler
  • Install the required plugin.
  • Restart the eclipse.

for reference, refer this link http://techno-terminal.blogspot.in/2016/05/jdk-18-compiler-compliance-is-not.html

marcolopes
  • 9,232
  • 14
  • 54
  • 65
satish
  • 1,571
  • 1
  • 11
  • 4
0

This is a old topic but I just wanted to point out that I have searched enough to find that Indigo version can't be updated to S.E 1.8 here the link which is given on eclipse website to update the Execution Environment but if you try it will throw error for Indigo.

Image//wiki.eclipse.org/File:ExecutionEnvironmentDescriptionInstallation.png this is the link where the Information about execution environment is given.

https://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler This shows the step by step to update Execution environment.

I have tried to update Execution environment and I got the same error.

PRAVEEN SONI
  • 71
  • 1
  • 1
0

Assuming you have already downloaded Jdk 1.8. You have to make sure your eclipse version supports Jdk 1.8. Click on "Help" tab and then select "Check for Updates". Try again.

HaroldSer
  • 2,025
  • 2
  • 12
  • 23
0

First install the JDK1.8 set to Path Open Eclipse and Open Eclipse Market Place option. Search for jdk 1.8 for kepler Install the required plugin. Restart the eclipse. Change compiler level to 1.8 from preferences. If still there is an error then click on the file and change the compiler setting explicitly to Jdk 1.8

marcolopes
  • 9,232
  • 14
  • 54
  • 65
Bikash Singh
  • 291
  • 4
  • 3
0
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
Rakhee
  • 1