How to create a fat jar for my JavaFX program?

Scott Palmer swpalmer at gmail.com
Mon Jul 20 18:26:25 UTC 2020


jlink and jdeps are module-based, so you do have to be careful.  Neither will work properly when you try to run it against a non-modular project (found that out the hard way when Java 11 broke the world by removing the EE modules from Java SE and no modules were available to replace them), but you can use them to make a JRE image from a set of modules, such as those supplied by OpenJFX.

I still think the .jmod files should be hosted by artifact repositories to make this work smoothly.  Downloading an SDK, seems so old-school when we have good dependency-management tools.

Once you have a JRE image that includes JavaFX, then your application Jar files (all of them, no need to make anything 'fat') can easily be bundled with that JRE using jpackage.

I have done Gradle scripts to do all that and it wasn’t difficult.

Scott

> On Jul 20, 2020, at 1:39 PM, Michael Paus <mp at jugs.org> wrote:
> 
> In order to create a real platform installer with jpackage and jlink/jdeps you don't have to use the java
> module system at all. Have a look at this tutorial which I co-autored together with Dirk Lemmermann:
> <https://github.com/dlemmermann/JPackageScriptFX>
> Michael
> 
> Am 20.07.20 um 19:25 schrieb Davide Perini:
>> Unfortunantly so few dependencies supports Java Modules this day, so fat JAR is the only way I can do it.
>> 
>> Thanks
>> 
>> Il 20/07/2020 02.50, Scott Palmer ha scritto:
>>> The JavaFX classes are there, but what about the native libraries?
>>> 
>>> A fat jar isn’t a good way to distribute a Java application these days. Now you should probably be using jpackage and/or jlink to bundle your application classes with a runtime suitable for running the application.
>>> 
>>> Scott
>>> 
>>>> On Jul 19, 2020, at 5:32 PM, Davide Perini <perini.davide at dpsoftware.org> wrote:
>>>> 
>>>> Hi all,
>>>> thanks for the great project, I love JavaFX.
>>>> 
>>>> I always used the maven plugin to crete fat jars with all my deps. The resulting jar is an executable one and ready to use.
>>>> 
>>>> This is my pom that create the fat jar.
>>>> 
>>>> but when I try to exceute the jar I get this error:
>>>> 
>>>> Error: JavaFX runtime components are missing, and are required to run this appli
>>>> cation
>>>> 
>>>> 
>>>> if I explode the fat jar I can see that there are the javafx class in it. what am I doing wrong?
>>>> 
>>>> Thanks
>>>> Davide
>>>> 
>>>> <plugin> <groupId>org.openjfx</groupId> <artifactId>javafx-maven-plugin</artifactId> <version>${javafx.maven.plugin.version}</version> <configuration> <mainClass>org.dpsoftware.FastScreenCapture</mainClass> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <outputDirectory>${project.build.directory}/</outputDirectory> <finalName>JavaFastScreenCapture</finalName> </configuration> <executions> <execution> <id>make-executable-jar-with-dependencies</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>org.dpsoftware.FastScreenCapture</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </execution> </executions> </plugin>
>>>> 



More information about the openjfx-dev mailing list