在 Ubuntu 上安装 Eclipse 和 Java 9 时出现问题

在 Ubuntu 上安装 Eclipse 和 Java 9 时出现问题

我有 Xubuntu 17.10。我尝试通过 apt-get 安装 Eclipse。当我尝试运行它时,我收到一个错误

An error has occurred. See the log file
/home/jaakko/.eclipse/org.eclipse.platform_3.8_155965261/configuration/1510564798671.log.

日志文件如下:

!SESSION 2017-11-13 11:19:57.077 -----------------------------------------------
eclipse.buildId=debbuild
java.version=9.0.1
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 2017-11-13 11:20:00.209
!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 2017-11-13 11:20:00.222
!MESSAGE Bundle initial@reference:file:plugins/org.eclipse.equinox.simpleconfigurator_1.0.301.dist.jar was not resolved.

!ENTRY org.eclipse.osgi 2 0 2017-11-13 11:20:00.256
!MESSAGE One or more bundles are not resolved because the following root constraints are not resolved:
!SUBENTRY 1 org.eclipse.osgi 2 0 2017-11-13 11:20:00.256
!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 2017-11-13 11:20:00.256
!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 2017-11-13 11:20:00.268
!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 2017-11-13 11:20:00.268
!MESSAGE Bundle org.eclipse.equinox.simpleconfigurator_1.0.301.dist [1] was not resolved.
!SUBENTRY 2 org.eclipse.equinox.simpleconfigurator 2 0 2017-11-13 11:20:00.268
!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 2017-11-13 11:20:00.281
!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)

我发现如果我使用 Java 9 就会出现此问题,但如果使用 Java 8 则不会出现此问题。

如何将 Eclipse 安装到我的计算机上以运行 Java 9?

答案1

Ubuntu 18.04 及更高版本

默认 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 包。

Eclipse Photon JDT 完全支持 Java 9:

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

笔记: 为了在 Eclipse 18.04 及更高版本中添加新的 Java 版本,例如 openjdk-11-jdk,请按照上面步骤 1-9 中列出的说明进行操作,只需将字符串替换java-9-openjdk为您要添加的 Java 版本即可已安装的 JRE


Ubuntu 17.10

我已经安装了 Eclipse Oxygen(Eclipse 的最新版本)和 openjdk-9-jdk,Eclipse 正在使用这个版本的 openjdk-9-jdk。如果您想将 openjdk-8-jdk 保留为新 Eclipse Oxygen 中使用的默认 Java 版本,您可以打开 Eclipse 并从 Eclipse 内部添加 openjdk-9-jdk,如下所示。

  1. 选择窗户->优先

  2. 在“首选项”窗口右侧的窗格中,单击Java将其展开。

  3. 双击已安装的 JRE

  4. 点击添加在首选项窗口左侧添加一个新的 JRE。

  5. 选择标准虚拟机并点击下一个

  6. 在 JRE Home 中:字段类型/usr/lib/jvm/java-9-openjdk-amd64(对于 32 位 Eclipse,请使用 i386 而不是 amd64)

  7. 在 JRE 名称:字段类型java-9-openjdk-amd64(对于 32 位 Eclipse,请输入 i386 而不是 amd64)

  8. 点击申请按钮。

  9. 现在已安装的 JRE在步骤 3 中,您可以单击已安装 JRE 列表中某个 JRE 左侧的复选框,将其选为默认 JRE,然后单击申请按钮应用默认安装的 JRE 中的更改。

相同的说明不适用于 Ubuntu 16.04 中 Eclipse 的默认版本。

答案2

  1. 您必须安装openjdk-8-jre

    sudo apt-get install openjdk-8-jre
    
  2. 接下来切换到jre-8版本:

    $ sudo update-alternatives --config java
    There are 2 choices for the alternative java (providing /usr/bin/java).
    
    Selection    Path                                            Priority   Status
    
    * 0            /usr/lib/jvm/java-9-openjdk-amd64/bin/java       1091      auto mode
      1            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
      2            /usr/lib/jvm/java-9-openjdk-amd64/bin/java       1091      manual mode
    
  3. 检查Java版本:

    $ java -version
    openjdk version "1.8.0_151"
    OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.17.10.2-b12)
    OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
    
  4. 启动 eclipse

相关内容