My final use case is to create an ImageJ (https://imagej.nih.gov/ij/) plugIn that creates and displays a webpage in a JavaFX WebView
ImageJ is irrelevant to this bug and this SSCCE illustrates the problem by creating a WebView plugin which is loaded and run by a small main program WebView_Plugin_Runner.
In short, the program crashes unless the WebView_Plugin_Runner main program also includes the org.openjfx/javafx-web dependency, even though the calling program makes no direct reference to it.
Plugins can use all other aspects of JavaFX providing they initialise JavaFX correctly providing they do not use WebView without the main calling WebView_Plugin_Runner including any javaFX dependencies.
import ij.plugin.PlugIn;
import java.net.URI;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class WebView_Plugin implements PlugIn {
@Override
public void run(String arg) {
Platform.startup(() -> {
});
Platform.runLater(() -> {
WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();
String url = "https://karyotyper.com/";
webEngine.load(URI.create(url).toString());
Scene scene = new Scene(webView);
Stage stage = new Stage();
stage.setTitle(arg + " - " + url);
stage.setScene(scene);
stage.show();
});
}
}
import ij.plugin.PlugIn;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
public class WebView_Plugin_Runner {
public static void main(String[] args) throws Exception {
File dir = new File("WebView_Plugin_-1.0.jar");
URL[] classUrl = new URL[]{dir.toURI().toURL()};
ClassLoader cl = new URLClassLoader(classUrl);
Class loadedClass = cl.loadClass("WebView_Plugin");
PlugIn plugin = (PlugIn) loadedClass.getDeclaredConstructor().newInstance();
plugin.run("PlugIn");
}
}
This complete SSCCS example (plugin and plugin runner) can be accessed at
https://gitlab.com/Michael51773/webview_plugin
https://gitlab.com/Michael51773/webview_plugin_runner
A more detailed explanation is available at
https://gitlab.com/Michael51773/webview_plugin/-/blob/master/README.md
Any help with this gratefully appreciated!
question from:
https://stackoverflow.com/questions/65905673/javafx-webview-crashes-if-invoked-from-a-plug-in 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…