Creating a simple HelloWorld application with JavaFX
11 and Maven
with only this dependency:
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
</dependencies>
This results in this dependency tree:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ javafx-module-test ---
[INFO] ch.sahits.test:javafx-module-test:jar:1.0-SNAPSHOT
[INFO] \- org.openjfx:javafx-controls:jar:11:compile
[INFO] +- org.openjfx:javafx-controls:jar:linux:11:compile
[INFO] \- org.openjfx:javafx-graphics:jar:11:compile
[INFO] +- org.openjfx:javafx-graphics:jar:linux:11:compile
[INFO] \- org.openjfx:javafx-base:jar:11:compile
[INFO] \- org.openjfx:javafx-base:jar:linux:11:compile
As you can guess from the above output I run this on a Linux machine which left me with an bad feeling regarding creating executable jar files that are portable to other OS. Therefore I went ahead and created such a jar file using the assembly plugin:
As you can see in the above image of the jar's content there are native libraries included. For Windows this would probably be some dlls.
How can we create an executable jar file for a JavaFX application that can be run anywhere?
The one way I could imagine is to require the OpenJFX runtime being installed on the target machine, so that it does not need to be bundled in the jar, but this is something to be avoided as it is very user unfriendly.