In a burst of enthusiasm, I spent the last few weeks creating a GUI frontend to the jpackage utility, slated for the upcoming JDK 14 release. I called the tool Installmation, a portmanteau of ‘installation’ and ‘automation’. It’s written in Kotlin and JavaFX, of course, and focuses on creating JavaFX application installers, but can create non-JFX applications.
Generally, you would script the creation of installer creation into your build process, but there are occasions when a simple UI tool is faster. No more remembering the arcane and fiddly parameters, cutting and pasting stuff between projects, and so on. Plus, it can generate batch files for you as well.
I suppose the ultimate test for an installer tool to create its own installer, sort of like how bacteria reproduce – binary fission. So, Installmation passed the binary fission test a few days ago – the installer is available here.
The tool has four capabilities:
- Create application images
- Create complete installers
- Generate standalone shell scripts to create images and installers
- List the module dependencies of an application
In this post, I will focus on creating complete installers. I will use it to create an OS X installer for one of my own repos. Generating scripts and module dependencies will be covered in another post, to keep this post mercifully brief.
Sadly, there is some stuff you will need to download and install first, but hey…cross-platform development has a long and rich history of being a pain in the ass. The suffering continues.
- jpackage – currently available in JDK 14 early access release
- JavaFX 11+ SDK
- JavaFX 11+ Jmods
- WINDOWS ONLY – jpackage requires the Wix Toolset installed and in your path
- clone my javafx-app-1 application, or use your own….
OS X Catalina Headaches
If you are running on OS X Catalina, most of the JDK 14 command line tools will not run due to Apple’s new GateKeeper security ‘feature’. I disabled mine with:
sudo spctl --master-disable
Which makes it behave like older OS X versions and allows all executables to run. This disables Gatekeeper, so use at your own risk. Here is some detail on it.
You will then have to double click on each of the following in Mac’s Finder to remove the warning from each executable (F%^&#$&!!):
This issue will go away when JDK 14 is officially released (March 2020) and the installer is properly signed by a verified Apple Developer Certificate.
Prepare the Target Application
The installer will require a few details about the application to be installed:
- A main class
- An application jar file
- Classpath items
The installer will do the rest, in terms of building a custom runtime by analysing your applications module dependencies.
I will use my own javafx-app-1 repo for this tutorial.
For the purposes of this post, I have added gradle tasks to the javafx-app-1 repo to makes things easier.
From inside javafx-app-1 repo directory, run the following gradle tasks from the command line:
gradlew jar gradlew libs
This will create the application jar in the build/libs/ directory, and a build/deplibs/ directory with all the dependencies. This is just for the purposes of this post.
Start the Application
You can either start the app after cloning the repo with gradlew runApp or download the binary from here.
It looks like this.
Create A New Project – app1
Create a new project and save it. All files are saved in the <user.home>/.installmation directory. Fill in the project name, and set the installer type to pkg. The other fields are optional and will default to sensible values.
Setup Install Directories
These 3 directories can be anywhere, but are populated during installer generation, and are recreated for every generation attempt.
Input Directory – Installmation copies all your project files to a single location, in a format easy for jpackage to process.
Image Build Directory – Location where jpackage will generate the packaged application. On OSX, this is an .app file, on Windows, multiple files and directories. You should be able to run this application out of the directory. This is a good smoke test to ensure everything works.
Installer Directory – Location where installer will be generated – .msi, .exe, .dmg, or .pkg files.
Setup Java Binaries
This dialog is more complicated than you would expect. Until JDK 14 is released and used everywhere, you will need to manage jpackage JDKs separately from your deployment JDK. Similarly, JavaFX 11+ is not a single install, but split into the libraries and mods downloads.
Jpackage – JDK which contains jpackage. This will be version 14 or better – the EA release (as of December 2019) works fine.
JDK to install – This is the JDK which will be customised into a runtime and added to your build image. This can be be any version (11+ for JavaFX, however).
Libraries – Optional. JavaFX libraries download. This is required only if you have Java 9 modules you need to add.
Jmods – Optional. Only used for JavaFX applications.
Setup Application Jar File and Main Class
This panel is straightforward – just set the full path of the main jar file and the main class name.
Add all you class path elements. The extra modules is optional and a bit experimental right now.
Generate the Installer
Save the project and hit the installer button and if everything went well, you should see the successful creation of an installer. It is created in the installer directory specified above.
The tool is pretty basic at this stage. It needs a lot more testing, and has a strong JavaFX bias. A lot of installer tools don’t support JavaFX directly so I made a concerted effort to do so. I made efforts to make the interface as intuitive as possible, but I am sure it could be improved, so any feedback would be great – just create issues in GitHub.
Some of things I will work on in the short term include:
- Splash screens and icons
- Custom configuration file deployment