为什么eclipse不会将编译器切换到Java 8? [英] Why won't eclipse switch the compiler to Java 8?

查看:585
本文介绍了为什么eclipse不会将编译器切换到Java 8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在eclipse中从SVN中签出了一个Java项目,并意识到它需要Java 8,因为它使用lambdas等。我为Java 8安装了eclipse插件,并重新启动了eclipse,并使项目设置如下:





我注意到,在底部附近,它表示默认的编译器合规性是1.7,所以我进入 org.eclipse.jdt.core.prefs 和将编译器合规性变量设置为 1.8 ,按



一旦获得Luna,您的JAVA_HOME变量应足以让Eclipse识别JDK 8.
如果要指定其他JDK,可以通过转到:



添加新的Java系统库pre> 项目 - >属性 - > Java构建路径 - >图书馆 - >添加库 - > Java系统库

并导航到JDK 8的有效位置。



您可以下载平台的JDK 8 这里


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

这篇关于为什么eclipse不会将编译器切换到Java 8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆