Nat
Nat

Reputation: 1

Exporting SWT with JavaFX WebView component as Runnable JAR from Eclipse results in NullPointerException

I am running into a problem, when using the export 'runnable jar' with Eclipse (Oxygen.2 Release (4.7.2)). The resulting JAR on Linux throws a null pointer exception within fwkScheduleDispatchFunctions.

Using the code as follows

package webview;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;

import javafx.embed.swt.FXCanvas; 
import javafx.scene.Scene;
import javafx.scene.web.WebView;

public class MainSWT2 {

    public static void main(String[] args) throws InterruptedException {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("JavaFX / SWT Integration");

    shell.setLayout(new FillLayout());
    FXCanvas fxCanvas = new FXCanvas(shell, SWT.NONE);
    WebView browser = new WebView();

    fxCanvas.setScene(new Scene(browser, 1024, 768));

    shell.pack();
    shell.open();

    browser.getEngine().load("http://www.google.com");

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }

    display.dispose();

    }   
}

And exporting the project as 'Runnable JAR file'

Export Properties

The resulting JAR file throws a null pointer when run from the command line:

$ SWT_GTK3=0 java -jar ~/swttest.jar
Exception in thread "Thread-2" java.lang.NullPointerException
at    com.sun.webkit.MainThread.fwkScheduleDispatchFunctions(MainThread.java:34)

When choosing 'Extract required libraries into generated JAR' the JAR runs fine.

Unfortunately I need to use this with a 'jar-in-jar' solution so Extracting the libraries does not work for me.

Any insight into what is going wrong would be greatly appreciated, thank you.

Java version:

$ java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

Upvotes: 0

Views: 371

Answers (1)

N'bia
N'bia

Reputation: 27

Could you try it as a maven project? After that depend your jar into the main project. you can use maven jar plugin.

Upvotes: 0

Related Questions