From d1c201bf4d1592184e5582d43925563af25eddf9 Mon Sep 17 00:00:00 2001 From: WANG CHAO <1229983126@qq.com> Date: Fri, 8 Feb 2019 22:31:56 +0800 Subject: [PATCH] change the entry point of addressbook After we add the javafx runtime dependency, addressbook is still unable to run in a jdk11 environment. It gives an error of below: Error: JavaFX runtime components are missing, and are required to run this application This error comes from sun.launcher.LauncherHelper in the java.base module. The reason for this is that the Main app extends Application and has a main method. If that is the case, the LauncherHelper will check for the javafx.graphics module to be present as a named module. If that module is not present, the launch is aborted. Hence, having the JavaFX libraries as jars on the classpath is not allowed in this case [1]. This is more like a JDK 11 problem which cannot be solved elegantly. One simple workaround is to have a separate main class that doesn't extend Application. Hence it doesn't do the check on javafx.graphics module, and when the required jars are on the classpath, it works fine. Let's add another main class to be the new entry point of addressbook to solve this problem [2]. [1] http://mail.openjdk.java.net/pipermail/openjfx-dev/2018-June/021977.html [2] https://stackoverflow.com/questions/52653836/maven-shade-javafx-runtime-components-are-missing/52654791#52654791 --- build.gradle | 2 +- src/main/java/seedu/address/Main.java | 25 ++++++++++++++++++++++++ src/main/java/seedu/address/MainApp.java | 6 +++--- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 src/main/java/seedu/address/Main.java diff --git a/build.gradle b/build.gradle index 76bc120f33a5..738cc752daf7 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ plugins { } // Specifies the entry point of the application -mainClassName = 'seedu.address.MainApp' +mainClassName = 'seedu.address.Main' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/src/main/java/seedu/address/Main.java b/src/main/java/seedu/address/Main.java new file mode 100644 index 000000000000..f88368154b18 --- /dev/null +++ b/src/main/java/seedu/address/Main.java @@ -0,0 +1,25 @@ +package seedu.address; + +/** + * The main entry point to the application. + * + * Addressbook is unable to run in a jdk11 environment using MainApp class + * directly and it gives an error of below: + * + * Error: JavaFX runtime components are missing, and are required to run this application + * + * This error comes from sun.launcher.LauncherHelper in the java.base + * module. The reason for this is that the Main app extends Application + * and has a main method. If that is the case, the LauncherHelper will + * check for the javafx.graphics module to be present as a named module. + * If that module is not present, the launch is aborted. + * + * One simple workaround is to have a separate main class that doesn't + * extend Application. Hence it doesn't do the check on javafx.graphics + * module, and when the required jars are on the classpath, it works fine. + */ +public class Main { + public static void main(String[] args) { + MainApp.initialize(args); + } +} diff --git a/src/main/java/seedu/address/MainApp.java b/src/main/java/seedu/address/MainApp.java index a92d4d5d71f0..dbc6ee0cc82d 100644 --- a/src/main/java/seedu/address/MainApp.java +++ b/src/main/java/seedu/address/MainApp.java @@ -32,7 +32,7 @@ import seedu.address.ui.UiManager; /** - * The main entry point to the application. + * Runs the application. */ public class MainApp extends Application { @@ -181,7 +181,7 @@ public void stop() { } } - public static void main(String[] args) { - launch(args); + public static void initialize(String[] args) { + Application.launch(MainApp.class, args); } }