如何使用 OpenJDK 9 修复 Eclipse

如何使用 OpenJDK 9 修复 Eclipse

我在 Ubuntu 17.10 中安装了 OpenJDK 9。我想开始用 Java 进行开发,我设置了 JAVA_HOME 变量并做了一些我在网上找到的东西。我可以编译并运行 Java 程序,但我无法安装 IDE,而这确实是必要的。

错误信息是:

发生错误。请参阅日志文件 /home/erik/.eclipse/org.eclipse.platform_3.8_155965261/configuration/1531145712071.log。

日志文件包含:

!SESSION 2018-07-09 16:15:11.911 -----------------------------------------------
eclipse.buildId=debbuild
java.version=9-Ubuntu
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Command-line arguments:  -os linux -ws gtk -arch x86_64

!ENTRY org.eclipse.equinox.simpleconfigurator 4 0 2018-07-09 16:15:12.423
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException: The bundle "org.eclipse.equinox.simpleconfigurator_1.0.301.dist [1]" could not be resolved. Reason: Missing Constraint: Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,J2SE-1.4
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolverError(AbstractBundle.java:1332)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.getResolutionFailureException(AbstractBundle.java:1316)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:323)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:390)
    at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1176)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
    at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
    at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
    at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)

!ENTRY org.eclipse.osgi 4 0 2018-07-09 16:15:12.429
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.equinox.simpleconfigurator_1.0.301.dist.jar was not resolved.

!ENTRY org.eclipse.osgi 2 0 2018-07-09 16:15:12.435
!MESSAGE One or more bundles are not resolved because the following root constraints are not resolved:
!SUBENTRY 1 org.eclipse.osgi 2 0 2018-07-09 16:15:12.435
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.equinox.simpleconfigurator_1.0.301.dist.jar was not resolved.
!SUBENTRY 2 org.eclipse.equinox.simpleconfigurator 2 0 2018-07-09 16:15:12.435
!MESSAGE Missing required capability Require-Capability: osgi.ee; filter="(|(&(osgi.ee=CDC/Foundation)(version=1.1))(&(osgi.ee=JavaSE)(version=1.4)))".

!ENTRY org.eclipse.osgi 2 0 2018-07-09 16:15:12.436
!MESSAGE The following is a complete list of bundles which are not resolved, see the prior log entry for the root cause if it exists:
!SUBENTRY 1 org.eclipse.osgi 2 0 2018-07-09 16:15:12.436
!MESSAGE Bundle org.eclipse.equinox.simpleconfigurator_1.0.301.dist [1] was not resolved.
!SUBENTRY 2 org.eclipse.equinox.simpleconfigurator 2 0 2018-07-09 16:15:12.436
!MESSAGE Missing required capability Require-Capability: osgi.ee; filter="(|(&(osgi.ee=CDC/Foundation)(version=1.1))(&(osgi.ee=JavaSE)(version=1.4)))".

!ENTRY org.eclipse.osgi 4 0 2018-07-09 16:15:12.437
!MESSAGE Application error
!STACK 1
java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:74)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1414)

答案1

默认 Ubuntu 存储库中的 Eclipse snap 包非常适合 Java 编程,因为它与 Java 开发环境捆绑在一起。要安装它,请打开终端并输入:

sudo snap install eclipse --classic  

此命令将安装最新的 Photon Release 4.8 版本的 Eclipse IDE for Java Developers,该版本于 8 天前更新。Eclipse 更改了其代号策略,以便从 2018 年 9 月起的 Eclipse 版本以发布日期的年份和月份命名,例如 Eclipse 2020-06。此命名方案也适用于 eclipse snap 包。

Photon JDT 完全支持 Java 9:

  • Eclipse Java 编译器 (ECJ) 实现了所有新的 Java 9 语言增强功能。
  • 更新了重要功能以支持 Java 模块,例如编译器、搜索和许多编辑器功能。

答案2

虽然我总是更喜欢来自 Ubuntu 发行版的软件包,但我对 Eclipse 却是个例外,因为它 (a) 安装很简单,(b) 必须以用户身份安装(不需要或推荐使用 root 身份),并且 (c) 它可以很好地管理自己的更新和插件 - 包括回滚等。

以下说明适用于所有 Eclipse IDE(Java、C/C++、Web、PHP 等)。

  1. 安装 JDK

    sudo apt install default-jdk
    
  2. 从以下网址下载最新的 Eclipse 安装程序eclipse.org。目前这是日蚀光子

  3. 将其解压到您选择的目录中

    mkdir -p ~/eclipse/installer
    tar -C ~/eclipse/installer -xzf ~/Downloads/eclipse-inst-linux64.tar.gz
    
  4. 运行安装程序

    cd ~/eclipse/installer
    ./eclipse-inst
    
  5. 选择你的 IDE 并按照提示操作

完成后,使用安装 IDE 的eclipse目录中的脚本启动 IDE 。eclipse

卸载任何 Eclipse IDE,只需rm -r其安装目录即可。如果您对 kruft 污染非常在意,那么也可以rm -rf ~/.eclipse

相关内容