为什么 eclipse 不会将编译器切换到 Java 8?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24947844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why won't eclipse switch the compiler to Java 8?
提问by itdoesntwork
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:
我在 Eclipse 中从 SVN 检查了一个 Java 项目,并意识到它需要 Java 8,因为它使用了 lambdas 等。我为 Java 8 安装了 Eclipse 插件并重新启动了 Eclipse,并像这样设置了项目:
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:
我注意到在底部附近,它说默认编译器合规性是 1.7,所以我进入org.eclipse.jdt.core.prefs
并将编译器合规性变量设置为1.8
,根据
这个答案。但是,在 Project -> Preferences -> Java Compiler 中,它仍然显示为:
I have set the JRE in Project -> Java Build Path:
我已经在 Project -> Java Build Path 中设置了 JRE:
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.
然而,编译器拒绝编译 lambda 表达式 - 我得到一个错误,看起来就像我继续将它输入到 Java 7 中会得到的一样。
This is the version of eclipse I'm using
这是我正在使用的 eclipse 版本
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?
解决此问题的唯一方法是安装新版本的 Eclipse 还是我在配置中遗漏了什么?
采纳答案by Ryan J
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.
首先,JRE 与 JDK 不同。如果你有 JDK,你需要在你的设置中配置 eclipse 以指向它。
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.
其次,在上面的屏幕截图中,您的编译器合规性级别设置为 1.7。这会将您的所有代码视为使用 Java 1.7。将此更改为 1.8 以修复您的错误。
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.
您需要安装 Eclipse Luna 才能获得对 Java 8 的支持,但如果您愿意,可以将其添加到 Kepler SR2。在您继续之前,我会尝试使用 Luna 和上述建议。请参阅此参考。
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:
一旦你得到 Luna,你的 JAVA_HOME 变量应该足以让 Eclipse 识别 JDK 8。如果你想指定一个额外的 JDK,你可以通过以下方式添加一个新的 Java 系统库:
Project -> Properties -> Java Build Path -> Libraries -> Add Library -> Java System Library
and navigating to a valid location for the JDK 8.
并导航到 JDK 8 的有效位置。
You can download your platform's JDK 8 here
您可以在此处下载您平台的 JDK 8
回答by teddy
It cause eclipse kepler SR1 does not support new Java? 8 language enhancements like lambda expression.
它导致 eclipse kepler SR1 不支持新的 Java?8 种语言增强功能,如 lambda 表达式。
From information here: http://www.eclipse.org/downloads/java8/
I think you should use kepler SR2 with support plugin, or change to Eclipse Luna.
从这里的信息:http: //www.eclipse.org/downloads/java8/
我认为您应该使用带有支持插件的开普勒 SR2,或者更改为 Eclipse Luna。
Updated link 16/09/2016: https://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler
更新链接 16/09/2016:https: //wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler
回答by Deepanshu J bedi
First of all you should get JdK 8.
首先你应该得到 JdK 8。
if you have Jdk installed.
如果你安装了 Jdk。
you should set its path using cmd prompt or system variables.
您应该使用 cmd 提示符或系统变量设置其路径。
sometimes it can happen that the path is not set due to which eclipse is unable to get the properties for jdk.
有时可能会发生路径未设置的情况,因为 eclipse 无法获取 jdk 的属性。
Installing latest ecipse luna can solve your problem.
安装最新的 ecipse luna 可以解决您的问题。
i have indigo and luna. i can set 1.8 in luna but 1.7 in indigo.Eclipse luna
我有靛蓝和月神。我可以在 luna 中设置 1.8 但在 indigo 中设置 1.7。月食
You can check the eclipse site. it says that the eclipse luna was certainly to associate the properties for jdk 8.
你可以查看eclipse站点。它说eclipse luna肯定会关联jdk 8的属性。
回答by Thomas R
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
新下载的 JDK 1.8.0
JAVA_HOME 已设置
命令行上的 java -version 报告 1.8
控制面板中的 Java 设置为 1.8
下载 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.
Eclipse 只让我在编译器首选项中选择编译器合规性级别 op 为 1.7,即使我安装的 JRE 是 1.8.0。我也无法在已安装 JRE 下的执行环境中看到 1.8,只有 JavaSE-1.7(我什至还没有安装!)。当我点击它时,它显示“jdk1.8.0”为兼容的 JRE,所以我选择了它,但仍然没有变化。
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:
然后我把Eclipse Mars解压到一个全新的目录,新建了一个项目,现在可以选择1.8了,呵呵!这大大减少了我在 Java 1.8 下编译代码时遇到的“名为 spliterator 的重复方法...”错误,但是,仍然有一个错误:
Duplicate default methods named spliterator with the parameters () and () are inherited from the types List and Set.
带有参数 () 和 () 的名为 spliterator 的重复默认方法继承自 List 和 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)
然而,这可能是因为我正在扩展 AbstractList 并实现 Set,所以我现在通过删除实现 Set 来解决这个问题,因为它在我的情况下并没有真正添加任何东西(除了表示我的集合只有唯一元素)
回答by tranan
You must install the JDT/Eclipse Java 8 Support For Kepler. https://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler
您必须安装 JDT/Eclipse Java 8 Support For Kepler。 https://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler
回答by satish
I had the similar problem with eclipse kepler.I have followed these steps to resolve it
我在 eclipse kepler 上遇到了类似的问题。我已经按照这些步骤来解决它
- Go to Help in Eclipse and Oper Eclipse Market Place option.
- Search for jdk 1.8 for kepler
- Install the required plugin.
- Restart the eclipse.
- 转到 Eclipse 中的帮助和 Oper Eclipse Market Place 选项。
- 为 kepler 搜索 jdk 1.8
- 安装所需的插件。
- 重新启动日食。
for reference, refer this link http://techno-terminal.blogspot.in/2016/05/jdk-18-compiler-compliance-is-not.html
作为参考,请参阅此链接http://techno-terminal.blogspot.in/2016/05/jdk-18-compiler-compliance-is-not.html
回答by PRAVEEN SONI
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.
这是一个老话题,但我只是想指出,我已经搜索了足够多的内容,发现 Indigo 版本无法更新到 SE 1.8,这里是 eclipse 网站上提供的更新执行环境的链接,但如果您尝试它会为 Indigo 抛出错误。
Image//wiki.eclipse.org/File:ExecutionEnvironmentDescriptionInstallation.png this is the link where the Information about execution environment is given.
Image//wiki.eclipse.org/File:ExecutionEnvironmentDescriptionInstallation.png 这是给出执行环境信息的链接。
https://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_KeplerThis shows the step by step to update Execution environment.
https://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler这显示了逐步更新执行环境。
I have tried to update Execution environment and I got the same error.
我尝试更新执行环境,但遇到了同样的错误。
回答by HaroldSer
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.
假设您已经下载了 Jdk 1.8。您必须确保您的 Eclipse 版本支持 Jdk 1.8。单击“帮助”选项卡,然后选择“检查更新”。再试一次。
回答by Bikash Singh
First install the JDK1.8 set to Path Open Eclipse and Oper 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
首先安装JDK1.8 设置为Path Open Eclipse 和Oper Eclipse Market Place 选项。搜索 jdk 1.8 for kepler 安装需要的插件。重新启动日食。从首选项将编译器级别更改为 1.8。如果仍然有错误,则单击该文件并将编译器设置显式更改为 Jdk 1.8
回答by ForeverLearner
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:
老问题,但发布答案以防它对某人有所帮助。已经将构建路径配置为使用 JDK 1.2.81 但是,构建失败并出现以下错误:
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.
在最新的 Eclipse (Photon) 中,将以下条目添加到 pom.xml 起作用了。
<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>