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:
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:
I have set the JRE in Project -> Java Build Path:
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?
解决方案
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