简体   繁体   English

如何将 AdoptOpenJDK 8 和 11 与 Oracle JDK 8 并行安装并与 Eclipse 一起使用

[英]How to install AdoptOpenJDK 8 and 11 parallel to Oracle JDK 8 and use both with Eclipse

I'm trying to update Java to Version 11, but don't want to use Oracles JDK because of the license.我正在尝试将 Java 更新到版本 11,但由于许可证的原因不想使用 Oracles JDK。 I also would like to install and use AdoptOpenJDK 8 because of that.因此,我也想安装和使用 AdoptOpenJDK 8。 My OS is Windows 10.我的操作系统是 Windows 10。

I've already tried to install AdoptOpenJDK 11 without overwriting any settings, as I want other java-programs to still run using Oracles JRE 8. I added the AdoptOpenJDK installation folder to the installed JREs in eclipse and when I ran some test code, "java.version" was set to 11.0.7, but when trying the new 'var' feature, Eclipse said that 'var' is not allowed here .我已经尝试在不覆盖任何设置的情况下安装 AdoptOpenJDK 11,因为我希望其他 java 程序仍然使用 Oracles JRE 8 运行。我将 AdoptOpenJDK 安装文件夹添加到 eclipse 中已安装的 JRE 中,当我运行一些测试代码时,“ java.version" 设置为 11.0.7,但是在尝试新的 'var' 功能时,Eclipse 说'var' is not allowed here I changed the compiler compliance level to 11 and updated to Eclipse Version 2020-03 (4.15.0), but it still didn't work.我将编译器合规级别更改为 11 并更新为 Eclipse 版本 2020-03 (4.15.0),但它仍然无法正常工作。
Then I reinstalled AdoptOpenJDK 11 and let the installer change all the settings, but it still wouldn't work.然后我重新安装了 AdoptOpenJDK 11 并让安装程序更改所有设置,但它仍然无法正常工作。

How can I install AdoptOpenJDK 8 and 11 parallel to OracleJDK 8 on my system and set in Eclipse which one to use per project?如何在我的系统上安装与 OracleJDK 8 并行的 AdoptOpenJDK 8 和 11,并在 Eclipse 中设置每个项目使用哪一个?

EDIT: Ok, it works now, apparently I just didn't understand how to use 'var' correctly.编辑:好的,它现在可以工作了,显然我只是不明白如何正确使用'var'。 Thank you for your help nonetheless.尽管如此,还是感谢您的帮助。

The error message 'var' is not allowed here means that you are using Java 10 or higher, but var is used somewhere in the code where you cannot .错误消息'var' is not allowed here表示您使用的是 Java 10 或更高版本,但var在您不能使用的代码中某处使用。 Otherwise, for a compiler compliance level lower than 10, you would get var cannot be resolved to a type .否则,对于低于 10 的编译器合规级别,您会得到var cannot be resolved to a type

Example:例子:

class Sample {

    var s = ""; // 'var' is not allowed here

    var foo() { // 'var' is not allowed here
        // ...
    }

    void foo(var x) { // 'var' is not allowed here
        // ...

        var s = ""; // okay

    }

}

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

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