Eclipse 说 jre 不支持当前的编译器级别 1.8 但它设置为 1.7

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31916579/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:47:21  来源:igfitidea点击:

Eclipse says jre does not support the current compiler level of 1.8 but it is set at 1.7

javaeclipse

提问by Jerry Murphy

I installed Eclipse mars with java JDK8 but was was having lots of problems with it so I uninstalled it changed back to JDK7 and now I'm getting a strange compiler error in a few of my projects. I noticed that when I went into, Windows->Preferences-> Java->Installed JREs, there is an error message at the top saying that "The selected JRE does not support the ...rent compiler compliance level of 1.8" but when I check the compiler compliance level its set to 1.7

我用 java JDK8 安装了 Eclipse mars,但它有很多问题,所以我卸载它改回 JDK7,现在我在我的一些项目中遇到了一个奇怪的编译器错误。我注意到当我进入 Windows->Preferences->Java->Installed JREs 时,顶部有一条错误消息说“所选的 JRE 不支持 ...rent 编译器合规性级别 1.8”但是当我检查编译器合规性级别设置为 1.7

Ok so I decided to try starting a new project and when trying to build it a warning came up that my workspace compliance level was at level 1.8...changing the workspace fixed the problem. So new is it possible to change the workspace compliance level or should I just import my projects into a new workspace?

好的,所以我决定尝试开始一个新项目,当尝试构建它时,出现了一个警告,即我的工作区合规性级别为 1.8 级……更改工作区解决了问题。那么新的是否可以更改工作区合规性级别,或者我应该将我的项目导入新的工作区?

I tried importing into a new workspace,same problem. So I started new project in a new workspace, copyed and pasted the code in a voila it works! Very annoying if I have to do that for every class in every project I want.

我尝试导入到一个新的工作区,同样的问题。所以我在一个新的工作区中开始了新项目,复制并粘贴了代码,瞧它有效!如果我必须为我想要的每个项目中的每个课程都这样做,那非常烦人。

回答by Charles Goodwin

Check your compliance settings in:

检查您的合规性设置:

Preferences > Java > Compiler

首选项 > Java > 编译器

Make sure the default is set to 1.7 as it may have defaulted to 1.8 after the initial install/run.

确保默认设置为 1.7,因为它可能在初始安装/运行后默认为 1.8。

Also check project-specific compliance settings in:

还要检查项目特定的合规性设置:

(Project) Properties > Java Compiler

(项目)属性 > Java 编译器

回答by Maslor

If you already changed all settings to 1.7 (both in the eclipse preferences and the project properties) check your project's build path. How? Easy, after you've imported your project, right-button click it and select Build path > Configure Build Path. Then, check if you have your JRE system library correctly set.

如果您已经将所有设置更改为 1.7(在 eclipse 首选项和项目属性中),请检查您的项目的构建路径。如何?很简单,在您导入项目后,右键单击它并选择构建路径 > 配置构建路径。然后,检查是否正确设置了 JRE 系统库。

If even this is set up ok, I would say that you probably have some code that can only be compiled by jdk 8 and you're trying to use jdk7 compliance level, which eclipse warns you about. An example of this is using lambda functions, which can only be compiled with java 8 as far as I know.

如果即使这样设置还可以,我会说您可能有一些只能由 jdk 8 编译的代码,并且您正在尝试使用 jdk7 合规级别,eclipse 会警告您。这方面的一个例子是使用 lambda 函数,据我所知,它只能用 java 8 编译。

回答by Janet

I changed Windows ->Preference->Java->Installed JREs to jdk1.7.0_79 and right clicked the project, Properties ->Java Build Path, made sure that under Libraries tab, it is JRE System Library[JavaSE-1.7]. Clicked Project ->Clean. Right clicked the project again, Properties ->Java Compiler, checked Use compliance from execution environment 'JavaSE-1.7' on the 'Java Build Path'.Then it worked. enter image description here

我将 Windows ->Preference->Java->Installed JREs 更改为 jdk1.7.0_79 并右键单击该项目,Properties ->Java Build Path,确保在 Libraries 选项卡下,它是 JRE System Library[JavaSE-1.7]。单击“项目”->“清理”。再次右键单击该项目,属性 -> Java 编译器,在“Java 构建路径”上选中“使用符合性来自执行环境“JavaSE-1.7”。然后它工作了。在此处输入图片说明

回答by Swapnil Gapchup

  1. Go to Windows >> Preferences>>Compiler >> Unselect default compliance settings >> select the compiler compliance level to 1.8

  2. This should reflect in generated .class files compatibility as 1.8 and source compatibility as 1.8 Step Step

  3. Apply it Step

  4. now click on apply and close

  5. clean and build the project.

  1. 转到 Windows >> 首选项 >> 编译器 >> 取消选择默认合规性设置 >> 选择编译器合规性级别为 1.8

  2. 这应该反映在生成的 .class 文件兼容性为 1.8 和源兼容性为 1.8 Step Step

  3. 应用步骤

  4. 现在点击应用并关闭

  5. 清理并构建项目。

回答by ro_flo_ce

I have similar issue with Mars on Pydev environment. Seems that Mars want java jre 1.7.0, so for me was work by copy inside(create if not avaiable) eclipse\jre\ folder and copy the 1.7.0 version of jre inside

我在 Pydev 环境中遇到了与 Mars 类似的问题。似乎火星想要 java jre 1.7.0,所以对我来说是通过复制里面的工作(如果不可用则创建)eclipse\jre\ 文件夹并复制里面的 jre 1.7.0 版本