如何将 org.eclipse.swt(和其他插件依赖项)添加为自动 Java9 模块? [英] How to add org.eclipse.swt (and other plugin dependencies) as an automatic Java9 module?

查看:34
本文介绍了如何将 org.eclipse.swt(和其他插件依赖项)添加为自动 Java9 模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了能够将我的 Eclipse 插件treezCore"也用作 Java9 模块,我在我的 src 文件夹中创建了一个 module-info.java.

此外,我将插件依赖项从类路径移至模块路径.我可以在插件依赖项中看到一个模块org.eclipse.swt.3.106.1.v20170926":

但是,我无法在我的 module-info.java 中引用该模块.我试过了

需要org.eclipse.swt.3.106.1.v20170926;需要 org.eclipse.swt;需要 swt;

这些选项都不起作用.Eclipse使用的jar文件pluginsorg.eclipse.swt_3.106.1.v20170926-0519.jar不包含模块定义和

jar --file org.eclipse.swt_3.106.1.v20170926-0519.jar -d

表示无法导出模块描述符.另见

如果我从

下载更新版本的 swt.jar

相关问题:

解决方案

您观察到的内容在 bug 525660,首先观察到 Eclipse 的所有现有 (OSGi) 工件都不能作为自动模块工作,因为 Java 9 无法从形状为 <代码>org.eclipse.swt_3.106.1.v20170926-0519.jar.

由于发现此问题为时已晚,无法请求改进自动模块名称派生算法,因此只能通过在未来版本的清单中添加 Automatic-Module-Name 标头来解决此问题.

此标头从 Photon M4 开始出现,如 org.eclipse.swt_3.107.0.v20171205-0742.jar,包含:

<块引用>

自动模块名称:org.eclipse.swt

In order to be able to use my Eclipse plugin "treezCore" also as a Java9 module I created a module-info.java in my src folder.

Furthermore, I moved the Plug-in Dependencies from the Classpath to the Modulepath. I can see a module "org.eclipse.swt.3.106.1.v20170926" in the plugin dependencies:

However, I am not able to reference that module in my module-info.java. I tried

require  org.eclipse.swt.3.106.1.v20170926;
require  org.eclipse.swt;
require  swt;

None of those options worked. The jar file pluginsorg.eclipse.swt_3.106.1.v20170926-0519.jar that is used by Eclipse does not contain a module definition and

jar --file org.eclipse.swt_3.106.1.v20170926-0519.jar -d

says that the module descriptor can not be derived. Also see

Unable to derive module descriptor for auto generated module names in Java 9?

If I download a newer version of swt.jar from

http://download.eclipse.org/eclipse/downloads/drops4/R-4.7.1a-201710090410/download.php?dropFile=swt-4.7.1a-win32-win32-x86_64.zip

I get following output that looks promising:

swt automatic
requires java.base mandated
contains org.eclipse.swt
contains org.eclipse.swt.accessibility
contains org.eclipse.swt.awt
contains org.eclipse.swt.browser
contains org.eclipse.swt.custom
contains org.eclipse.swt.dnd
contains org.eclipse.swt.events
contains org.eclipse.swt.graphics
contains org.eclipse.swt.internal
contains org.eclipse.swt.internal.gdip
contains org.eclipse.swt.internal.image
contains org.eclipse.swt.internal.mozilla
contains org.eclipse.swt.internal.mozilla.init
contains org.eclipse.swt.internal.ole.win32
contains org.eclipse.swt.internal.opengl.win32
contains org.eclipse.swt.internal.webkit
contains org.eclipse.swt.internal.win32
contains org.eclipse.swt.layout
contains org.eclipse.swt.ole.win32
contains org.eclipse.swt.opengl
contains org.eclipse.swt.printing
contains org.eclipse.swt.program
contains org.eclipse.swt.widgets

I also depend on org.eclipse.jface and could not find a seperate download for it.

=> Do I really have to wait for a new release of Eclipse that uses new plugin versions including module definitions?

Or can I somehow reference the old version of swt from the plugins folder, even if it does not include a module definition? I looked for an easy way to define an alias or a fallback dependency e.g.

requires ../plugins/org.eclipse.swt_3.106.1.v20170926-0519.jar as 'org.eclipse.swt'

or

requires org.eclipse.swt fallback ../plugins/org.eclipse.swt_3.106.1.v20170926-0519.jar 

but module-info.java does not seem to support such a syntax.

I have about 20 plugin dependencies and do not want to manually download each of them (if it would be possible) and include them as external jar file. Nor do I want to hack the individual Manifest/jar files in the Eclipse plugin folder. There are many jar files I would need to alter and an update of Eclipse would break that hack.

I am using Eclipse for RCP and RAP Developers, Version: Oxygen.1a Release (4.7.1a), Build id: 20171005-1200

Edit

When using Version: Photon Milestone 4 (4.8.0M4) Build id: 20171214-1849, the error in module-info.java vanishes when using

require org.eclipse.swt;

and having the Plug-in Dependencies in the Modulepath.

However, my imports do not work yet, see following image. If I move the Plug-in Dependencies from the Modulepath to the Classpath, the imports work but the error in module-info.java reappears.

I created a min example at

https://github.com/stefaneidelloth/Java9EclipsePluginExample/tree/master/MyPlugin

and I filed a bug report at

https://bugs.eclipse.org/bugs/show_bug.cgi?id=529089

Related questions:

解决方案

What you observe is tracked in bug 525660, which starts with the observation that all existing (OSGi) artifacts of Eclipse don't work as automatic modules, because Java 9 fails to derive a valid module name from jar filenames of the shape org.eclipse.swt_3.106.1.v20170926-0519.jar.

Since this was discovered too late to request improving the algorithm for automatic module name derivation, this can only be fixed by adding Automatic-Module-Name headers to the manifests of future releases.

This header is present starting from Photon M4 as can be seen in org.eclipse.swt_3.107.0.v20171205-0742.jar, containing:

Automatic-Module-Name: org.eclipse.swt

这篇关于如何将 org.eclipse.swt(和其他插件依赖项)添加为自动 Java9 模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆