A Java Packaging Tool That Enables Double‑Click Execution
The author reviews common Java desktop packaging methods—GraalVM, JLink, Exe4J, batch scripts, and plain JAR—detailing their advantages and drawbacks, then demonstrates a custom WinForm‑based packaging utility that bundles a Swing application and a trimmed JRE into a single executable for double‑click launch.
Java Swing applications cannot run directly on machines without a JRE, which limits their distribution as desktop tools. The article first lists the typical ways to package Java programs for end users:
Compile the JAR into a native binary with GraalVM .
Use JLink to create a custom runtime image and package it as a binary.
Generate a launcher with Exe4J and wrap it in a self‑extracting archive.
Write a batch script and bundle it similarly in a self‑extracting archive.
Distribute the plain JAR and require users to install a JRE and launch it manually.
The author then compares these approaches, summarizing their pros and cons:
GraalVM : improves performance and reduces resource usage, but the build is time‑consuming, debugging is hard, and reflection support is limited.
JLink : produces a lightweight binary, yet the build process is complex, debugging remains difficult, and the resulting file can be large.
Exe4J : lowers the usage barrier and offers a better user experience, but the executable is bulky and still requires a JRE, making it unsuitable for tiny tools.
Batch script : easy to configure and update, but the package size is large and it also depends on a JRE.
Plain JAR : smallest distribution size and easy to update, yet it cannot run on machines without a JRE and the command‑line start-up hurts usability.
Because binary distribution is hard to debug and plain JARs give a poor user experience, the author builds a custom packaging tool using WinForm. The tool takes a Swing program, creates a slim JRE, and packages both into an .exe that can be launched with a double‑click.
The article provides a complete Maven pom.xml configuration that uses the maven-assembly-plugin to create a “fat JAR” (including all dependencies) and specifies the main class org.hellloswing.HelloSwing. It also shows the source code of HelloSwing.java, which sets up a FlatLaf theme, creates a JFrame with a label, and displays the window.
After building the fat JAR, the author extracts a minimal JRE, runs the custom WinForm packager, and produces an executable that bundles the JAR and the JRE. The final result is a double‑click‑able program, as demonstrated by screenshots of the tool UI and the packaged application.
Finally, the author notes that this work is recorded for reference and includes a brief self‑promotion for a project‑sharing community, which is unrelated to the technical content.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
SpringMeng
Focused on software development, sharing source code and tutorials for various systems.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
