Eclipse 2018-09不会编译Java 11源代码;认为它低于1.7 [英] Eclipse 2018-09 won't compile Java 11 source; thinks it is below 1.7

查看:363
本文介绍了Eclipse 2018-09不会编译Java 11源代码;认为它低于1.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 10上运行Eclipse 2018-09(4.9.0)。我正在使用Open JDK 11 GA。我有一个Maven项目被指定为使用Java 8源代码。

I'm running Eclipse 2018-09 (4.9.0) on Windows 10. I'm using Open JDK 11 GA. I have a Maven project that was specified as using Java 8 source code.

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

在命令行上使用Maven 3.5.3编译好。使用Eclipse Eclipse 2018-09(4.9.0)编译也很好。

That compiles fine using Maven 3.5.3 on the command line. That also compiles fine using Eclipse Eclipse 2018-09 (4.9.0).

我将编译Java版本更改为Java 11:

I changed the compile Java versions to Java 11:

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>11</maven.compiler.source>
  <maven.compiler.target>11</maven.compiler.target>
</properties>

使用Maven 3.5.3在命令行上仍然可以正常运行。但是在Eclipse 2018-09中,我得到了错误:

That still builds fine on the command line using Maven 3.5.3. But in Eclipse 2018-09, I get errors all over the place:


  • '<>'运算符不允许源级别低于1.7

  • 仅在源级别1.8或以上允许构造函数引用

  • 仅在源级别1.8或以上允许使用默认方法

  • '<>' operator is not allowed for source level below 1.7
  • Constructor references are allowed only at source level 1.8 or above
  • Default methods are allowed only at source level 1.8 or above

你明白了。

我已经用 Alt + F5 来在Eclipse中更新我的Maven项目(和子项目)。我已经完成了一个完整的清理和重建。

I've already used Alt+F5 to update my Maven project (and subprojects) in Eclipse. I've done a complete clean and rebuild.

因为这在命令行上与Maven编译得很好,所以这必须是一个Eclipse问题,不是吗?当然,Eclipse不支持所有新的Java 11功能,但此代码没有Java 11特定功能。出了什么问题?

Because this compiles fine with Maven on the command line, this has to be an Eclipse problem, doesn't it? Sure, Eclipse doesn't support all new Java 11 features, yet, but this code has no Java 11 specific features. What's wrong?

推荐答案

听起来Eclipse没有从pom中获取版本。

It sounds like Eclipse is not picking up the versions from the pom.

我刚刚测试了你的pom配置,并通过提供编译器源代码和目标属性(如问题或新发布属性如本答案中所述,使用最新的 Java 11支持Eclipse 2018-09 插件。

I just tested your pom configuration and verified that it works, either by providing compiler source and target properties like in the question or the new release property as described in this answer, using the latest Java 11 Support for Eclipse 2018-09 plugin.

在Eclipse首选项中正确设置JDK 11非常重要。在已安装的JRE首选项页面上添加JDK 11,然后将其与执行环境首选项页面上的JavaSE-11进行匹配。否则,更新Maven项目将导致使用默认的JDK,这可能是您遇到的问题。

It is important that the the JDK 11 is correctly set up in the Eclipse preferences. Add the JDK 11 on the "Installed JRE" preference page and then match it with the JavaSE-11 on the "Execution Environment" preference page. Otherwise updating the Maven project will result in the default JDK being used, which is likely the issue that you are having.

这篇关于Eclipse 2018-09不会编译Java 11源代码;认为它低于1.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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