Bundling - GeoInter/Leguan GitHub Wiki
With the introduction of Java 9, the bundling and deployment of Java applications has changed. For the Leguan Simulator, non-modular dependencies make building executables more difficult. The dependencies in question are ANTLR and RichtextFX. The following explains how bundling is currently handled.
Basically, leave the dependencies/modules as they are and generate a shaded/fat jar with the maven-shade plugin. Executables are built from this jar. The downside is that the jar has to contain all JavaFX dependencies for all platforms and all their architectures. For the pom.xml you would need to specify the dependencies. Currently to geenrate a multi-platform executable the following commands are being run for each platform:
-
Windows:
mvn clean package "-Djavafx.platform=win" "-Dapp.name=Leguan.exe" -P exe -f .\build_pom.xml
-
Linux:
mvn clean package "-Djavafx.platform=linux" "-Dapp.name=Leguan-linux.sh" -P shell -f .\build_pom.xml
-
Mac-Aarch64:
mvn clean package "-Djavafx.platform=mac-aarch64" "-Dapp.name=Leguan-mac-aarch64.sh" -P shell -f .\build_pom.xml
Note: You would need to specify all platforms + architectures as stated in JavaFX parent pom. Since the classes specified in each module overlap it has to be done individually.
JLink and JPackage can be used to bundle a jar, but only work if all dependencies are modular. This would require building Java 9+ jars from source, which kind of defeats the purpose of Maven and automatic dependency handling. On top the fat jar of richtext has a different name than its original. Meaning you would also need to edit the module-info file. But since there no more options here are the steps:
Download the fat jar from the Richtext repo and install the jar locally: mvn org.apache.maven.plugins:maven-install-plugin:3.1.1:install-file -Dfile=".\libs\richtextfx-fat-0.11.2.jar" -DgroupId="org.fxmisc.richtext.fat" -DartifactId="richtextfx.fat" -Dversion="0.11.2" -Dpackaging="jar" -DgeneratePom=true Adjust the pom.xml groupId and artifactId according to the command and change the module name in the module info to richtext.fat (set name).
- Donwload the source and build module info with this command: jdeps --generate-module-info .\src\org C:\Users<USER>.m2\repository\org\antlr\antlr4-runtime\4.11.1\antlr4-runtime-4.11.1.jar
- Patch the generate module info into the jar: javac --patch-module org.antlr.antlr4.runtime=C:\Users\Besitzer.m2\repository\org\antlr\antlr4-runtime\4.11.1\antlr4-runtime-4.11.1.jar .\org.antlr.antlr4.runtime\module-info.java
- Install the dependency: mvn org.apache.maven.plugins:maven-install-plugin:3.1.1:install-file -Dfile=".\libs\antlr4-runtime-4.13.1.jar" -DgroupId="org.antlr.antlr4.runtime" -DartifactId="antlr4-runtime.fat" -Dversion="4.13.1" -Dpackaging="jar" -DgeneratePom=true
With this steps done all dependencies should now be modular and compatible with jlink and jpackage.
mvn clean package "-Djavafx.platform=win" -P exe -f .\build_pom.xml
mvn clean package "-Djavafx.platform=mac-aarch64" -P shell -f .\build_pom.xml