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_HOMEto its directory. - On Windows, install the Visual Studio Build Tools with the Desktop development with C++
workload.
native-imageneeds its C toolchain, and the plugin needsrc.exeto put the icon and the version into the executable.
Build the executable
-
On Windows, open an x64 Native Tools Command Prompt for VS, or run
vcvars64.batfirst, so that the toolchain is on thePATH. -
Build the executable:
./gradlew nativeCompileThe executable is
build/native/nativeCompile/notes, ornotes.exeon Windows. It is about 26 MB and carries the pages of the application. -
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-accessfor the calls into the system,-Osfor a small file, and a heap capped at 64 MB, which a desktop application rarely needs more of. - Every file of
src/main/resourcesgoes 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.plistwith the bundle identifiercom.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