Repository navigation
10. Build a native executable
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.
- 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.
-
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 nativeCompile
The 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.
To give the application to people who have Java 25, build a distribution that runs on their Java runtime instead:
./gradlew installDistThe 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
Tutorial
- Set up the project
- Open a window
- Call Java from the page
- Send events from Java to the page
- Draw your own title bar
- Export notes through a native dialog
- Keep the application in the tray
- Show notifications
- Give the application an icon and a name
- Build a native executable
- Package the application
Guides
- Pass objects through the bridge
- Stream bytes between the page and Java
- Open several windows
- Place and control a window
- Make a transparent window
- Add menus
- Register global shortcuts
- Show progress in the taskbar
- Use the clipboard
- Handle dropped files
- Zoom the page
- Set the window icon
- Follow the theme of the desktop
- Use cookies
- Store data in SQLite
- Keep secrets
- Show dialogs
- Run a single instance
- Open your own links and files
- Update the application
- Handle page permissions
- Handle links and page loads
Reference