0

I am using OpenJDK 11 + OpenJavafx 11 environment in Eclipse Photon 2018-12 and created one plugin GUI project in eclipse. My aim is to add the OpenJavafx components(Button) on SWT Part.

These are steps I am following to render the javafx Button on top of SWT Part

Application e4xmi view:

Application.e4xmi

There are two plugins using

1. com.rcp.main – Main RCP Application, there are two parts on part stack in main plugin.

Part 1 (Sample Part 1 : class URI bundleclass://com.rcp.main/com.rcp.main.parts.SamplePart) Rendered with pure SWT created from eclipse template figure below. It is working as expected.

part 1 Screenshot

Part 2 (Sample Part 2: class URI bundleclass://com.rcp.main/com.rcp.main.parts.SamplePart1) Rendered with open Javafx GUI components (Button) on SWT part. I am getting empty one exception from as figure below

Part 2 Screenshot

2. com.rcp.feature – This feature included plugins with com.rcp.main and org.eclipse.fx.osgi

VM Arguments in Product file:

-Dorg.osgi.framework.bundle.parent=ext -Dosgi.framework.extensions=org.eclipse.fx.osgi --module-path "C:\Program Files\Java\javafx-sdk-11.0.1\lib" --add-modules javafx.base,javafx.controls,javafx.graphics --add-modules ALL-MODULE-PATH

public class SamplePart {

    private TableViewer tableViewer;

    @Inject
    private MPart part;

    @PostConstruct
    public void createComposite(Composite parent) {
        parent.setLayout(new GridLayout(1, false));

        Text txtInput = new Text(parent, SWT.BORDER);
        txtInput.setMessage("Enter text to mark part as dirty");
        txtInput.addModifyListener(e -> part.setDirty(true));
        txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

        tableViewer = new TableViewer(parent);

        tableViewer.setContentProvider(ArrayContentProvider.getInstance());
        tableViewer.setInput(createInitialDataModel());
        tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    }

    @Focus
    public void setFocus() {
        tableViewer.getTable().setFocus();
    }

    @Persist
    public void save() {
        part.setDirty(false);
    }

    private List<String> createInitialDataModel() {
        return Arrays.asList("Sample item 1", "Sample item 2", "Sample item 3", "Sample item 4", "Sample item 5");
    }
}




public class SamplePart1 {
    @Inject
    private MPart part;

    @PostConstruct
    public void createComposite(Composite parent) {
        final FXCanvas fxCanvas = new FXCanvas(parent, SWT.NONE);
        fxCanvas.setLayout(new GridLayout(1, true));
        try {
            Button btn = new Button();
            btn.setText("Say 'Hello World'");
            StackPane root = new StackPane();
            root.getChildren().add(btn);
            Scene scene = new Scene(root);
            fxCanvas.setScene(scene);
        } catch (Exception e1) {

        }
    }

    @PreDestroy
    @Inject
    private void disposeARView(MWindow window, EModelService modelService) {

    }

    @Focus
    public void setFocus() {

    }

    @Persist
    public void save() {

    }
}

I am getting this exception when i click the Part 2 tab on part stack

Result:

Empty Screen in Part 2

!ENTRY org.eclipse.e4.ui.workbench 4 0 2019-02-05 09:55:46.956
!MESSAGE Unable to create class 'com.rcp.main.parts.SamplePart1' from bundle '82'
!STACK 0

org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Canvas

Caused by: java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Canvas
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1095)

Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Canvas
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • NoClassDefFoundError often means that the class is present but not visible to your plugin project because the correspondent package or plugin import in your MANIFEST.MF is missing. – Robert Feb 05 '19 at 12:01
  • Do you have a file `module-info.java`? OSGi does not work well with *--module-path*. I recommend developing with -classpath instead (no `module-info.java`). – ZhekaKozlov Feb 06 '19 at 10:22

0 Answers0