Foojay Today

JavaFX Templates for Desktop Applications

October 15, 2021



Here on Foojay we already talked about JavaFX write-once-run-everywhere applications and how they can be created on GitHub with Gluon and GraalVM:

In this post, we are going to take a look at other different approaches.

Modularized JavaFX Template with Gradle by Gerrit Grunwald

This is a little project on GitHub that can be used as a template for modularized JavaFX projects, based on JDK17. You can import the build.gradle file as a project into your IDE and start the application by using gradlew Main from the command line or from within the IDE.

The running template application

You will find three script files

  • build_app_windows.bat

...which can be used to build native packages and installers on the platform of your choice. If you would like to build a native package on MacOS you need to perform the following steps:

./gradlew clean build

After the script has finished you will find the dmg, the pkg and the app file in the folder


In addition the project also comes with a github action in the folder


The ci.yml file will build the native packages for each platform on GitHub after each push to the project. The artifacts will be attached to the build so that you can download it from there.

JPackageScriptFX by Dirk Lemmermann and Michael Paus

This project, originally created by Michael Paus was turned into a template project by Dirk Lemmermann. It demonstrates how projects can use scripts to build self-contained, platform-specific executables and installers of their JavaFX applications via the jdeps, jlink, and jpackage tools. Two scripts are included for running builds on Mac/Linux and Windows. The jpackage tool is bundled with the JDK since version 14.

The project in this repository uses a multi-module Maven setup with a parent module containing three child modules. One of these child modules is the "main" module as it contains the main class. This module also contains the build scripts and its target directory will contain the results of the build. The JavaFX application consists of a single-window displaying three labels. The first one shows the currently configured locale and the other two labels get imported from module 1 and module 2 respectively.

alt text
The second template application

The platform-specific versions are created with Maven and this whole process is very well and detailed explained in the README file of the GitHub project.

maven-jpackage-template by Will Iverson

And there is even one more Maven template project we can share here! It generates a custom JVM and installer package for a JavaFX application. It can easily be adapted to work with Swing instead.

The generated installers come in at around 30-40MB. The example source in the project includes demonstrations of several native desktop features - for example, drag-and-drop from the Finder/Explorer, as well as a few macOS Dock integration examples. Removing the code and the demonstration dependencies gets a "Hello World" build size closer to 30MB.

Build with GitHub Actions

All three projects produce the promised platform-specific runtime with GitHub Actions.


Both for Maven and Gradle lovers there are different possibilities to build Java executables and GitHub provides the free tools to do so.

Thanks to Gerrit, Michael, Dirk, Will, and other contributors - who share these kinds of templates - getting started with JavaFX for desktop applications became easier again!


Related Articles

View All


  • Avatar photo
    Frank Delporte

    Frank Delporte (@frankdelporte) is a Java developer, technical writer at Azul, blogger, author of "Getting started with Java on Raspberry Pi", and contributor to Pi4J. Frank blogs about his experiments ... Learn more

Comments (0)

Your email address will not be published.

Highlight your code snippets using [code lang="language name"] shortcode. Just insert your code between opening and closing tag: [code lang="java"] code [/code]. Or specify another language.

Save my name, email, and website in this browser for the next time I comment.

Subscribe to foojay updates:
Copied to the clipboard