简体   繁体   中英

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

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

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>

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:

  • '<>' 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. 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? Sure, Eclipse doesn't support all new Java 11 features, yet, but this code has no Java 11 specific features . What's wrong?

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

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.

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.

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.


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)

It seams that the plugin is not available in Eclipse Marketplace anymore. 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

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

You don't need to upgrade eclipse in case you have the option to set the jdk 11 compiler.

**Note: Go to the Java Compiler post selecting the project properties and then Click on Configure Workspace settings to mention JDK 11.

JDK 11 编译器设置

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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