This is an example of a desktop application that can be built on top of cljfx/java stack. It uses:
JDK 14 introduced a new tool called jpackage that can pack a jar with a JDK into a
platform-specific executable. Previously packaging java-based apps for distribution was
one of the pain points compared to web: one had to strip down the JDK and figure
out how to pack it for every platform themselves. Now the year of Clojure on the desktop
is finally right around the corner, all you need is this small example.
The code is pretty simple: hn.core is a main namespace that starts
an app in its -main function. Note that it uses (Platform/setImplicitExit true) so
closing the window will stop JavaFX application thread. This, together with custom daemon
executor for agents, will allow to gracefully stop exit the app just by closing the app
window.
The build process is 2-step:
- Assemble an uberjar. Here it's done using Sean Corfield's
depstar library with
clj -A:uberjaralias. - Use
jpackagewith common options described in jpackage/common and platform-specific options having their own files: jpackage/linux, jpackage/mac and jpackage/windows. This is as simple as callingjpackage @jpackage/common @jpackage/linuxon Linux.
Cross-compiling is not supported by jpackage, so you will need access to all 3 OSes to assemble desktop packages. This repo has an example of github actions to create all 3 desktop packages: .github/workflows/build-release-artifacts.yml. Also note that JavaFX has platform-specific native libraries for every platform, which means uberjar needs to be assembled separately for every platform.