简体   繁体   English

Eclipse 2018-09 不会编译 Java 11 源代码; 认为它低于 1.7

[英]Eclipse 2018-09 won't compile Java 11 source; thinks it is below 1.7

I'm running Eclipse 2018-09 (4.9.0) on Windows 10. I'm using Open JDK 11 GA.我在 Windows 10 上运行 Eclipse 2018-09 (4.9.0)。我使用的是 Open JDK 11 GA。 I have a Maven project that was specified as using Java 8 source code.我有一个指定为使用 Java 8 源代码的 Maven 项目。

<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>

That compiles fine using Maven 3.5.3 on the command line.在命令行上使用 Maven 3.5.3 编译得很好。 That also compiles fine using Eclipse Eclipse 2018-09 (4.9.0).使用 Eclipse Eclipse 2018-09 (4.9.0) 也可以很好地编译。

I changed the compile Java versions to Java 11:我将编译 Java 版本更改为 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>

That still builds fine on the command line using Maven 3.5.3.使用 Maven 3.5.3 在命令行上仍然可以很好地构建。 But in Eclipse 2018-09, I get errors all over the place:但是在 Eclipse 2018-09 中,我到处都是错误:

  • '<>' 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

You get the idea.你明白了。

I've already used Alt+F5 to update my Maven project (and subprojects) in Eclipse.我已经使用Alt+F5在 Eclipse 中更新我的 Maven 项目(和子项目)。 I've done a complete clean and rebuild.我已经完成了彻底的清理和重建。

Because this compiles fine with Maven on the command line, this has to be an Eclipse problem, doesn't it?因为在命令行上使用 Maven 编译得很好,所以这一定是 Eclipse 问题,不是吗? Sure, Eclipse doesn't support all new Java 11 features, yet, but this code has no Java 11 specific features .当然,Eclipse 尚不支持所有新的 Java 11 功能,但此代码没有 Java 11 特定功能 What's wrong?怎么了?

It sounds like Eclipse is not picking up the versions from the pom.听起来 Eclipse 没有从 pom.xml 文件中获取版本。

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.我刚刚使用最新的Java 11 Support for Eclipse 2018-09插件测试了您的 pom 配置并验证了它是否有效,方法是提供问题中的编译器源和目标属性或本答案中描述的新版本属性。

It is important that the the JDK 11 is correctly set up in the Eclipse preferences.在 Eclipse 首选项中正确设置 JDK 11 很重要。 Add the JDK 11 on the "Installed JRE" preference page and then match it with the JavaSE-11 on the "Execution Environment" preference page.在“已安装的 JRE”首选项页面上添加 JDK 11,然后将其与“执行环境”首选项页面上的 JavaSE-11 进行匹配。 Otherwise updating the Maven project will result in the default JDK being used, which is likely the issue that you are having.否则更新 Maven 项目将导致使用默认的 JDK,这可能是您遇到的问题。

Update: Java 11 is fully integrated in Eclipse since Version 4.10 (released 2018-12-19), so one do not need to install this plugin anymore.更新: Java 11从 4.10 版(2018 年 12 月 19 日发布)开始完全集成Eclipse 中,因此不再需要安装此插件。


For some reason you need to install an additional Eclipse Plugin " Java 11 Support for Eclipse 2018-09 (4.9) " (even in Eclipse Photon 4.9)出于某种原因,您需要安装一个额外的 Eclipse 插件“ Java 11 Support for Eclipse 2018-09 (4.9) (即使在 Eclipse Photon 4.9 中)

It seams that the plugin is not available in Eclipse Marketplace anymore.看来该插件在 Eclipse Marketplace 中不再可用。 I someone find its install url, please add it here:我有人找到了它的安装网址,请在此处添加:

Works for Eclipse - STS 4.0.1 (based on Eclipse 4.9) , Maven 3.6.0, with this Maven Compiler Plugin Configuration适用于 Eclipse - STS 4.0.1(基于 Eclipse 4.9)、Maven 3.6.0,带有这个 Maven Compiler Plugin Configuration

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>11</source>
                <target>11</target>
            </configuration>                
        </plugin>

This problem is fixed in Eclipse 2018-12.此问题已在 Eclipse 2018-12 中修复。 Upgrading to that version will resolve your issue.升级到该版本将解决您的问题。

No need to add any plugin.无需添加任何插件。

You only need to upgrade eclipse such that it can handle jdk 11 compiler like mentioned in the attachment.您只需要升级 eclipse,使其可以处理附件中提到的 jdk 11 编译器。

You don't need to upgrade eclipse in case you have the option to set the jdk 11 compiler.如果您可以选择设置 jdk 11 编译器,则无需升级 eclipse。

**Note: Go to the Java Compiler post selecting the project properties and then Click on Configure Workspace settings to mention JDK 11. **注意:转到 Java 编译器帖子,选择项目属性,然后单击配置工作区设置以提及 JDK 11。

JDK 11 编译器设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM