I have a modular JavaFX application with the following Java code:
package webbrowser;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebView;
import javafx.scene.web.WebEngine;
import javafx.stage.Stage;
public class WebBrowser extends Application {
@Override
public void start(Stage stage) {
WebView browser = new WebView();
WebEngine webEngine = browser.getEngine();
webEngine.load("http://www.oracle.com");
Scene scene = new Scene(browser, 500, 500);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Here is the module-info.java file:
module webBrowser {
requires javafx.controls;
requires javafx.web;
exports webbrowser;
}
I compile the modular JavaFX application with the following command:
javac -d out --module-source-path . --module-path $JAVAFX_SDK/libs:$JAVAFX_JMODS --module webBrowser
I package the modular JavaFX application with the following command:
jpackage --type dmg --module-path $JAVAFX_JMODS:$JAVAFX_SDK/lib:out --add-modules javafx.controls,javafx.web,javafx.graphics,javafx.media --module webBrowser/webbrowser.WebBrowser
Then I save the application in my /Applications folder (I'm on Mac OS) and open the application. The application opens a 500x500 window, but it doesn't render any graphics, and it doesn't open a web browser. The application just opens a white blank 500x500 window.
Why isn't the application running properly?
When I run the application with java (and forego jpackage) the application runs fine in the JVM, opens a web browser, and opens the oracle.com webpage.
java --module-path out:$JAVAFX_JMODS:$JAVAFX_SDK/lib --add-modules javafx.controls,javafx.web --module webBrowser/webbrowser.WebBrowser
Why doesn't the application work when I use jpackage, install the dmg and run the Mac OS app?
The section of the openjfx.io documentation on runtime images, modular from CLI, demonstrates some of the points outlined below and provides examples of the command line arguments to use for compiling, linking, packaging and executing the application.
I suggest you get the linked openjfx demo working in your environment, then try the same for your project.
Some issues to address:
jmods can't be used at runtime, only at compile or link time.
--add-modules is not required for java/javac when you have a module-info.java.
--add-modules, you don't need to list the javafx package because it can work that out from your module-info.Your lib directory is inconsistent, always use the same (correct) directory:
lib and sometimes you use libs.Provide an onError handler.
When using jpackage you should have only the JavaFX mods.
Further points to check are highlighted in the answer to:
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