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

To be able to use my Eclipse plugin "treezCore" as well as the Java9 module, I created module-info.java in my src folder.

In addition, I have moved the dependencies of the plug-in from the Classpath to the module. I see the module "org.eclipse.swt.3.106.1.v20170926" in the dependencies of the plugin:

enter image description here

However, I cannot reference this module in my module-info.java. I tried

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

None of these options worked. The jar \ plugins \ org.eclipse.swt_3.106.1.v20170926-0519.jar file used by Eclipse does not contain a module definition and

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

says the module descriptor cannot be displayed. Also see

Can't get a module descriptor for automatically 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 the following output, which 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 rely on org.eclipse.jface and cannot find a separate download for it.

=> Do I need to wait for a new version of Eclipse, which uses new versions of the plugin, including module definitions?

Or can you somehow refer to the old version of swt from the plugins folder, even if it does not include a module definition? I was looking for an easy way to define an alias or fallback dependency, for example.

 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 this syntax.

I have about 20 plugin dependencies and you don’t want to manually download each of them (if possible) and include them as an external jar file. I also don't want to hack individual manifest / jar files in the Eclipse plugin folder. There are many jar files that I will need to modify, and an Eclipse update will break this hack.

I use 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 disappears when using

org.eclipse.swt required;

and with plug-in dependencies in the module path.

However, my import is not working yet, see the following figure. If I move the plug-in dependencies from the Pathpath module to Classpath, the import will work, but the error in module-info.java will reappear.

I created a minimal example in

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

and I sent an error report to

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

enter image description here

Related questions:

  • How to use third-party library in Java9 module?

  • Can't get a module descriptor for auto-generated module names in Java 9?

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

  • JFace offline download libraries (not selected from Eclipse plugins)

  • New keywords in Java 9

+2
swt java-9 eclipse-plugin eclipse-rcp jigsaw
source share
1 answer

What you are observing is tracked in bug 525660 , which begins by observing that all existing (OSGi) Eclipse artifacts do not work as automatic modules because Java 9 cannot get a valid module name from jar filenames of the form org.eclipse.swt_3.106.1.v20170926-0519.jar .

Since it was discovered too late to request an improvement in the algorithm for automatically displaying the module name, this can only be eliminated by adding the Automatic-Module-Name headers to the manifests of future releases.

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

Automatic-Module-Name: org.eclipse.swt

+5
source share

All Articles