Skip to content

Commit

Permalink
change the entry point of addressbook
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fzdy1914 committed Mar 31, 2019
1 parent 0cded97 commit d1c201b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/seedu/address/Main.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import seedu.address.ui.UiManager;

/**
* The main entry point to the application.
* Runs the application.
*/
public class MainApp extends Application {

Expand Down Expand Up @@ -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);
}
}

0 comments on commit d1c201b

Please sign in to comment.