I'm just trying to get the basic Hello World (project Trial0) application running using:
Following the (kinda ancient, it's about JDK 1.4 and SWT 3.1) description in Developing SWT applications using Eclipse, I have imported the SWT project into Eclipse:
I immediately hit a modularization/Jigsaw snag in a project that uses the imported SWT project. The compiler apparently is not allowed to see the SWT classes, which are not modularized:
"The package org.eclipse.swt.widgets is not accessible"
In this code:
package trial;
import org.eclipse.swt.widgets.*; // "The package org.eclipse.swt.widgets is not accessible"
public class MyApp {
}
Here is the project:

Note the module-info.java file on the importing project. It contains:
module trial0 {
requires java.desktop;
}
The swt.jar indeed does not advertise modules:
$ jar --file=swt.jar --describe-module
No module descriptor found. Derived automatic module.
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.accessibility.gtk
contains org.eclipse.swt.internal.cairo
contains org.eclipse.swt.internal.dnd.gtk
contains org.eclipse.swt.internal.gtk
contains org.eclipse.swt.internal.image
contains org.eclipse.swt.internal.opengl.glx
contains org.eclipse.swt.internal.webkit
contains org.eclipse.swt.layout
contains org.eclipse.swt.opengl
contains org.eclipse.swt.printing
contains org.eclipse.swt.program
contains org.eclipse.swt.widgets
Do I need to add module-info.java files to the SWT jar? Is there another "canonical" way of pulling the SWT jar up into modularization-land?
As you could see based on the output describing the module from the jar file.
In your module-info.java file, you shall add the following directive:
requires swt;
This would provide you the access to the package org.eclipse.swt.widgets which the module swt(automatic module name) claims to
contains org.eclipse.swt.widgets
in its description itself.
The file module-info.java of the importing project now contains:
module trial0 {
requires java.desktop;
requires swt;
}
Eclipse attaches this warning to the line requires swt;:
Name of automatic module 'swt' is unstable, it is derived from the module's file name.
That's ok.
The above may still not not work. In that case, verify the following:
The project org.eclipse.swt is on the importing project's Modulepath, instead of Classpath:

There needs to be an access rule on the imported module. The following access rules seems to work:

Note that there is nothing specific defined in the "Module Dependencies" for the importing project:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With