Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abhinayagarwal/maven-jlink-plugin-javafx
Using maven-jlink-plugin with JavaFX applications
https://github.com/abhinayagarwal/maven-jlink-plugin-javafx
Last synced: about 2 months ago
JSON representation
Using maven-jlink-plugin with JavaFX applications
- Host: GitHub
- URL: https://github.com/abhinayagarwal/maven-jlink-plugin-javafx
- Owner: abhinayagarwal
- Created: 2021-03-31T16:04:41.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-01T19:13:36.000Z (almost 4 years ago)
- Last Synced: 2024-10-31T15:47:55.359Z (3 months ago)
- Language: Java
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Using maven-jlink-plugin with JavaFX
This is a playground to use [maven-jlink-plugin](https://github.com/apache/maven-jlink-plugin) with JavaFX application.
## Create native image
```
mvn jlink:jlink
```## Problem
Using v3.1.0 of the plugin, `mvn jlink:jlink` fails with the following exception:
```
Error: automatic module cannot be used with jlink: javafx.graphicsEmpty
```Plugin logs have the following lines in them:
```
[INFO] --- maven-jlink-plugin:3.1.0:jlink (default-cli) @ hellofx ---
[INFO] -> module: javafx.base ( ~/.m2/repository/org/openjfx/javafx-base/13/javafx-base-13-linux.jar )
[INFO] -> module: javafx.graphicsEmpty ( ~/.m2/repository/org/openjfx/javafx-graphics/13/javafx-graphics-13.jar )
[INFO] -> module: hellofx ( ~/Documents/git/samples/IDE/IntelliJ/Modular/Maven/hellofx/target/classes )
[INFO] -> module: javafx.baseEmpty ( ~/.m2/repository/org/openjfx/javafx-base/13/javafx-base-13.jar )
[INFO] -> module: javafx.controls ( ~/.m2/repository/org/openjfx/javafx-controls/13/javafx-controls-13-linux.jar )
[INFO] -> module: javafx.graphics ( ~/.m2/repository/org/openjfx/javafx-graphics/13/javafx-graphics-13-linux.jar )
[INFO] -> module: javafx.fxml ( ~/.m2/repository/org/openjfx/javafx-fxml/13/javafx-fxml-13-linux.jar )
[INFO] -> module: javafx.fxmlEmpty ( ~/.m2/repository/org/openjfx/javafx-fxml/13/javafx-fxml-13.jar )
[INFO] -> module: javafx.controlsEmpty ( ~/.m2/repository/org/openjfx/javafx-controls/13/javafx-controls-13.jar )
```JavaFX tries to be platform independent by hiding the platform specific jars behind empty dependencies. If we add the following dependency to an application running on Linux:
```
org.openjfx
javafx-graphics
13```
It will be resolved into `javafx-graphics-13.jar` and `javafx-graphics-13-linux.jar`. The former is an empty jar with `Automatic-Module-Name` set as `javafx.graphicsEmpty`. More information on this can be found here: http://mail.openjdk.java.net/pipermail/openjfx-dev/2018-August/022313.html
## Solution
Most Java(FX) applications with a main class will add a `launcher` configuration to the plugin. If a launcher is found, `maven-jlink-plugin` can skip adding the entire module-path to the add-modules list and add only the base module to it. This is how [javafx-maven-plugin](https://github.com/openjfx/javafx-maven-plugin)'s `jlink` goal works.
This approach may have some side-effects and needs to be explored.