How to Create a Windows Installer for an SWT Application
In this article
To create a Windows installer for an SWT application, you package your compiled Java code and the SWT native libraries into a single executable using a tool like Inno Setup, NSIS, or jpackage (available in JDK 14+). The key is to include the correct SWT JAR for your target architecture (x86_64 or x86), bundle a compatible Java Runtime Environment (JRE) if you want the app to run without a separate Java install, and configure the installer to place files in the right directories and create shortcuts. This guide walks you through the process using jpackage and Inno Setup, the most reliable free options.
What You'll Need
- Your SWT application compiled into a runnable JAR (or a set of JARs including the SWT library for Windows).
- A Java Development Kit (JDK) version 14 or later (for jpackage) — JDK 17 or 21 LTS recommended.
- Inno Setup (free) if you want more control over the installer UI and shortcuts.
- The SWT JAR file for Windows (e.g.,
org.eclipse.swt.win32.win32.x86_64_<version>.jar) matching your JVM architecture. - A Windows machine to build and test the installer (cross-compiling from other OSes is not supported by jpackage).
Step-by-Step
- Prepare your application JAR. Build your SWT app into an executable JAR. Ensure the manifest specifies the main class (
Main-Class) and that all dependencies (including SWT) are on the classpath. If you use Maven or Gradle, use the shade or assembly plugin to create a fat JAR, but exclude the SWT JAR from the fat JAR — you will bundle it separately to avoid conflicts with native libraries. - Collect the SWT native library. Download the SWT JAR for Windows from the official Eclipse SWT site. Place it in a folder alongside your application JAR. The SWT JAR contains the
.dllfiles inside; jpackage will extract them automatically when building the runtime image. - Create a runtime image with jpackage (optional but recommended). Open Command Prompt or PowerShell and run:
jpackage --type app-image --name MySWTApp --input lib --main-jar myapp.jar --main-class com.example.Main --dest output
Replacelibwith the folder containing your JARs, andmyapp.jarwith your main JAR. This creates a self-contained folder with a private JRE and your app. Test it by runningoutput\MySWTApp\MySWTApp.exe. - Generate a Windows installer with jpackage. If the app-image works, build the installer:
jpackage --type exe --name MySWTApp --input lib --main-jar myapp.jar --main-class com.example.Main --win-shortcut --win-menu --win-dir-chooser --dest output
This produces an.exeinstaller in theoutputfolder. The--win-shortcutand--win-menuflags create desktop and Start Menu shortcuts. - Alternatively, use Inno Setup for more control. If you need custom installer pages, license agreement, or file associations, use Inno Setup. First, create the app-image with jpackage (step 3). Then open Inno Setup Compiler, create a new script, and point the
[Files]section to the entire app-image folder. Add[Icons]entries for shortcuts and[Run]to launch the app after install. Compile to get a single.exeinstaller. - Test the installer on a clean Windows machine. Run the installer on a PC without Java installed. Verify that the app launches, SWT widgets render correctly, and no missing DLL errors appear. Check that shortcuts work and the app can be uninstalled via Settings > Apps.
- Sign the installer (optional). To avoid SmartScreen warnings, sign the
.exewith a code-signing certificate usingsigntoolfrom the Windows SDK. This step is optional but recommended for distribution.
Common Mistakes
- Bundling the wrong SWT JAR. Using a 32-bit SWT JAR with a 64-bit JVM (or vice versa) causes
UnsatisfiedLinkErrorat runtime. Always match the SWT JAR to your JVM architecture. - Forgetting to include SWT native libraries. If you use a plain JAR without jpackage, the SWT
.dllfiles must be extracted and placed next to the JAR or in thejava.library.path. jpackage handles this automatically. - Not testing on a clean machine. Your development machine has Java and DLLs cached; a clean VM reveals missing dependencies.
- Using a fat JAR that includes SWT. This can cause duplicate native library loading and conflicts. Keep SWT as a separate JAR.
- Ignoring the
--win-dir-chooserflag. Without it, jpackage installs to a default location that may require admin rights; users cannot choose.
Tips
- Use JDK 17 or 21 LTS for jpackage; newer versions may have subtle bugs.
- Keep your app-image and installer builds in separate output folders to avoid confusion.
- If your app uses SWT
Browserwidget, ensure the Edge WebView2 runtime is installed on target machines (jpackage does not bundle it). - For Inno Setup, use
PrivilegesRequired=lowestif you don't need admin rights, so users can install without UAC prompts. - Add a
--win-consoleflag during testing to see console output from your app for debugging.
Troubleshooting
If the installer builds but the app fails to launch, first run the app-image executable directly from the command line to see error messages. Common issues include missing msvcr100.dll (install Visual C++ Redistributable), SWT version mismatch, or a missing --main-class argument. If jpackage fails with “Invalid or unsupported type”, ensure you are on Windows and using a JDK that includes jpackage. If the installer runs but shortcuts are missing, check that --win-shortcut and --win-menu were passed. For Inno Setup, verify that the [Files] section includes all files from the app-image folder, including the runtime subfolder. If you see java.lang.UnsatisfiedLinkError: no swt-win32-... in java.library.path, the SWT JAR is not on the classpath or the native library was not extracted — use jpackage to avoid this. Finally, test with antivirus disabled temporarily; some AV software blocks unsigned installers.
Frequently Asked Questions
Can I create a Windows installer for an SWT app without jpackage?
Yes, you can use Inno Setup or NSIS directly, but you must manually bundle a JRE and extract SWT native libraries. jpackage automates this and is recommended for JDK 14+.
Do I need to install Java on the target machine?
No, if you use jpackage with a runtime image, the installer includes a private JRE. Users do not need Java installed.
Why does my SWT app crash with “UnsatisfiedLinkError” after installation?
This usually means the SWT JAR is missing or the native .dll files were not extracted. Ensure the SWT JAR is in the --input folder and that you are using the correct architecture.
Can I sign the installer to avoid SmartScreen warnings?
Yes, use signtool with a code-signing certificate. This is optional but improves trust.
Does jpackage support 32-bit Windows?
jpackage can create 32-bit installers only if you use a 32-bit JDK. Most modern systems are 64-bit; check your target audience.
How do I add a custom icon to the installer?
Use the --icon flag with jpackage (point to an .ico file), or set the SetupIconFile directive in Inno Setup.