Reputation: 1021
Let's say I installed Oracle JDK 11 (just to make thing simpler). Then I downloaded Gluon's JavaFX 11 and unpacked in on top of JDK. Actually it doesn't matter where I unpack JavaFX (because my next aim is to make my own JRE installer based on OpenJRE). Then I am trying to start the application:
c:\Program Files\MyApp>"c:\Program Files\Java\jre-11\bin\java"
--module-path="c:\Program Files\Java\jre-11\lib"
--add-modules=javafx.controls
--add-modules=javafx.base -jar ./MyApp.jar
And I get this:
Error occurred during initialization of boot layer java.lang.LayerInstantiationException: Package jdk.internal.jrtfs in both module java.base and module jrt.fs
It I try to delete "jrs.fs" then my application crushes because some important system classes related to the class loader are missing. What is the proper way to start JavaFX applications with Java 11? And do I need to redistribute JavaFX every time with every application now (because now it's location must be specified in the command line that launches the application).
Upvotes: 5
Views: 1703
Reputation: 126
I have found that when converting from Java 8 to Java 11, you can just add OpenJfx as dependencies under Maven (assuming you are using Maven). eg
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.1-ea+1</version>
</dependency> etc
then you can run
java -cp .;.\lib --module-path .\lib;. --add-modules javafx.controls,javafx.graphics,javafx.fxml,javafx.web,javafx.swing -jar MyApp.jar
where Java 11 is in the Path, and all your Maven dependencies (modular or otherwise) are in the lib
subdirectory. Module dependencies do have to be added to the add-modules
list.
I have subsequently found that you have fewer issues if the modules are placed in a another directory, eg, the javafx modules (plus anything in the add-modules)
java -cp .;.\lib --module-path .\modules;. --add-modules javafx.controls,javafx.graphics,javafx.fxml,javafx.web,javafx.swing -jar MyApp.jar
Upvotes: 1