如何在Eclipse插件中使用Java11(Java10)?

8
如果我在我的Eclipse插件中将JavaSE-10指定为最低执行环境:

enter image description here

当我作为Eclipse应用程序启动我的插件时,出现以下错误:

enter image description here

org.osgi.framework.BundleException: Could not resolve module: org.treez.core [597]
  Unresolved requirement: Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)(version=10))"
  Unresolved requirement: Require-Bundle: org.treez.javafxd3; visibility:="reexport"
    -> Bundle-SymbolicName: org.treez.javafxd3; bundle-version="1.0.0.qualifier"; singleton:="true"
       org.treez.javafxd3 [586]
         Unresolved requirement: Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)(version=10))"

    at org.eclipse.osgi.container.Module.start(Module.java:444)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1634)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.incStartLevel(ModuleContainer.java:1613)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.doContainerStartLevel(ModuleContainer.java:1585)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.java:1528)
    at org.eclipse.osgi.container.ModuleContainer$ContainerStartLevel.dispatchEvent(ModuleContainer.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)

我检查了一下:

  • Java10 在已安装的JRE中被推崇
  • 10 被选为兼容级别

我使用 Oxygen.3a Release (4.7.3a) Build id: 20180405-1200

=>这是Eclipse Equinox中的一个bug吗?

=>我还能检查什么以解决这个问题?

enter image description here

如果我从最小执行环境设置中移除JavaSE-10,我就能启动Eclipse应用程序并且插件似乎可以正常工作。
当我导出插件时,会出现以下警告:
# 25.04.18, 12:25:40 MESZ
# Eclipse Compiler for Java(TM) v20180330-0919, 3.13.102, Copyright IBM Corp 2000, 2015. All rights reserved.
option -bootclasspath not supported at compliance level 9 and above

当我在更新页面安装插件后尝试使用它时,出现了ClassNotFoundException错误。
...
Caused by: java.lang.ClassNotFoundException: org.treez.views.tree.TreeViewPart cannot be found by org.treez.views_1.0.0.201804191641
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:564)
    at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:174)
    ... 114 more

如果我使用Java8,一切都正常。
相关问题:

3
我也看到了这个问题。据我所见,这是一个漏洞。 - greg-449
3
bootclasspathй”ҷиҜҜжҳҜдёҖдёӘеҚ•зӢ¬зҡ„й”ҷиҜҜпјҢе·ІеңЁжӯӨеӨ„жҠҘе‘Ҡпјҡhttps://bugs.eclipse.org/bugs/show_bug.cgi?id=525280гҖӮ - greg-449
3个回答

1
看起来Eclipse OSGi还不支持Java SE 10,我下载了最新的Eclipse Oxygen 4.7.3a并打开了plugins/org.eclipse.osgi_3.12.100.v20180210-1608.jar。最后一个支持的配置文件是JavaSE-9。
因此,你有两个选择:
等待OSGi官方支持JavaSE-10配置文件。
如果你真的想使用Java 10编写插件,并且你可以控制插件文件夹(例如,你正在开发Eclipse RCP应用程序),则可以打开OSGI jar并添加一个新的配置文件JavaSE-10。要做到这一点,你可以复制JavaSE-9.profile到JavaSE-10.profile,并在新文件中修复相应的行。此外,你必须在profile.list中添加一行。

4
可能是Eclipse的Bug [533731]。 - greg-449

0

对我而言可行的解决方法是:

  • 从清单文件中删除所需版本条目并忽略相应的警告

  • 在导出向导中激活“使用工作区编译的类文件”选项:

enter image description here

因此,我认为如果不应用该选项,则在导出向导的编译步骤中会出现错误。

我使用的是Java 11.0.1和Eclipse SimRel 2018-09(加上Java11支持插件)。


0

自OSGi 4.3以来,指定最低Java版本的最合适方式是使用Required-Capability头,如下所示:

Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version>=1.10))"

我已经成功地通过将所有Bundle-RequiredExecutionEnvironment的出现替换为上述行来修复报告的错误。在PDE中,您可能会收到有关清单文件的警告,但可以安全地忽略它。产品验证和产品导出似乎没有问题。

BREE头的语义要求OSGi实现为JRE的每个特定版本提供执行环境描述符。在Equinox中,这通常通过“.profile”文件定义;这些配置文件已被Equinox支持到JavaSE-9,但已宣布Equinox不再为新版本的Java提供配置文件。

Tycho社区已经通过创建自己的Java 10配置文件来处理此问题,但无法直接从PDE使用。 P2社区正在考虑复制Tycho的Java 10配置文件,但这已经停滞了很长时间。我不确定当提供不包含BREE头的捆绑包时,P2目前的反应如何。


尝试使用Java11,但这对我的情况没有帮助。清单文件仍然有警告,并且我仍然收到ClassNotFoundException Caused by: java.lang.ClassNotFoundException: org.treez.views.properties.PropertyViewPart cannot be found by org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:612) at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:180) ... 117 more。 - Stefan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接