Do you want your ad here?

Contact us to get your ad seen by thousands of users every day!

[email protected]

JavaFX Templates for Desktop Applications

  • October 15, 2021
  • 12686 Unique Views
  • 3 min read
Table of Contents

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
  • build_app_macos.sh
  • build_app_linux.sh

...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
bash build_app_macos.sh

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

fxmodules/build/installer

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

fxmodules/.github/workflows

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.

Conclusion

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!

How to Create Mobile Apps with JavaFX (Part 1)

In this three-part series, I’ll show how to use JavaFX for mobile app development: JavaFX looks great and runs on both mobile platforms.

You use the same JavaFX code targeting Google Play and Apple App stores. Performance is excellent and startup time is fast with native images.

You use Java 11+ and the latest JavaFX.

Our game is TiltMaze Labyrinth!

How to Create Mobile Apps with JavaFX (Part 2)

In Part 1, we introduced a mobile app game, TiltMaze, written completely in JavaFX, which you can download from either the Apple App Store or Google Play and install it on your mobile device or tablet.

In this article, we’ll discuss the technologies we use with JavaFX to build the JVM byte code version as well as native images that target iOS and Android devices.

How to Create Mobile Apps with JavaFX (Part 3)

In Part 1, we introduced a mobile app game, TiltMaze, written completely in JavaFX, which you can download from either the Apple App Store or Google Play and install it on your mobile device or tablet.

In Part 2, we showed you how to work with Gluon and GraalVM to build native images that execute on either Apple or Android mobile devices and tablets.

In this article, we’ll discuss how to upload your application to the respective mobile app stores so the world can install your application on their devices.

Cross-Platform Development in Java with Gluon and GraalVM (Part 1)

Gluon has invested heavily in R&D to create a full technology stack over the past five years. Gluon now offers a complete end-to-end Java solution, enabling Java developers to work productively on a secure and mature platform.

In short: Gluon is the company you’re looking for if you want an end-to-end Java solution. Gluon offers products that fit right into your company’s architecture.

Cross-Platform Development in Java with Gluon and GraalVM (Part 2)

Gluon is a company that enables Java on desktop, embedded, and mobile with a rich, full-featured, JavaFX user interface.

Gluon embeds GraalVM and brings GraalVM to an audience hungry for performance and full-featured user experiences.

Gluon enables seamless cloud integration of mobile and embedded experiences, driving increased cloud consumption.

Do you want your ad here?

Contact us to get your ad seen by thousands of users every day!

[email protected]

Comments (0)

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.

No comments yet. Be the first.

Subscribe to foojay updates:

https://foojay.io/feed/
Copied to the clipboard