Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add org.eclipse.swt (and other plugin dependencies) as an automatic Java9 module?

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:

enter image description here

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 \plugins\org.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?

enter image description here

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

enter image description here

Related questions:

  • How to use 3rd party library in Java9 module?

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

  • Force Eclipse (Helios) to use a newer version of SWT at application runtime

  • JFace libraries stand-alone download (not picked from Eclipse plug-ins)

  • New Keywords in Java 9

like image 524
Stefan Avatar asked Jan 29 '23 01:01

Stefan


1 Answers

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

like image 105
Stephan Herrmann Avatar answered Feb 11 '23 14:02

Stephan Herrmann