10. Build a native executable - fakeivchenko/lwjwae GitHub Wiki

The application runs with ./gradlew run, on the Java runtime of your machine. To give it to people who have no Java installed, build it as a native executable with GraalVM: one file that starts in a fraction of a second and needs no JVM.

Before you begin

  • Install GraalVM for JDK 25, and set GRAALVM_HOME to its directory.
  • On Windows, install the Visual Studio Build Tools with the Desktop development with C++ workload. native-image needs its C toolchain, and the plugin needs rc.exe to put the icon and the version into the executable.

Build the executable

  1. On Windows, open an x64 Native Tools Command Prompt for VS, or run vcvars64.bat first, so that the toolchain is on the PATH.

  2. Build the executable:

    ./gradlew nativeCompile
    

    The executable is build/native/nativeCompile/notes, or notes.exe on Windows. It is about 26 MB and carries the pages of the application.

  3. Run it:

    build/native/nativeCompile/notes
    

You changed nothing in the build for this. The plugin applies the GraalVM Native Build Tools plugin and configures it for lwjwae:

  • The image gets --enable-native-access for the calls into the system, -Os for a small file, and a heap capped at 64 MB, which a desktop application rarely needs more of.
  • Every file of src/main/resources goes into the image, so the pages load from the executable as they do from the JAR file. The lwjwae modules bring the metadata of their own native calls.
  • On Windows, the executable opens no console window, and carries the icon and the version block from the previous page.
  • On macOS, the executable carries an Info.plist with the bundle identifier com.example.notes, which the processes of WebKit need.

Note: A native image runs on the operating system and the processor that built it. Build the Linux executable on Linux, the Windows one on Windows, and the macOS one on macOS, for example on the runners of a CI service.

Without GraalVM

To give the application to people who have Java 25, build a distribution that runs on their Java runtime instead:

./gradlew installDist

The application is in build/install/notes. Start it with bin/notes, or with bin/notes.bat on Windows.


Previous: Give the application an icon and a name ยท Next: Package the application