Skip to main content

Windows

Windows-specific properties go in winConfig. Code signing is explained in the code signing guide, and the tools to install in the Windows tools guide.

Maven
<winConfig>
<icoFile>assets/windows/MyApp.ico</icoFile>
<exeCreationTool>launch4j</exeCreationTool>
<headerType>gui</headerType>
<generateSetup>true</generateSetup>
<generateMsi>true</generateMsi>
<msiUpgradeCode>3f1c0e5a-8a7e-4f53-9d1b-0a6a2d1f6c11</msiUpgradeCode>
<productVersion>1.2.0.0</productVersion>
<setupMode>askTheUser</setupMode>
<setupLanguages>
<english>compiler:Default.isl</english>
<spanish>compiler:Languages\Spanish.isl</spanish>
</setupLanguages>
<disableRunAfterInstall>false</disableRunAfterInstall>
</winConfig>
Gradle
javapackager {
winConfig {
icoFile = file('assets/windows/MyApp.ico')
exeCreationTool = 'launch4j'
headerType = 'gui'
generateSetup = true
generateMsi = true
msiUpgradeCode = '3f1c0e5a-8a7e-4f53-9d1b-0a6a2d1f6c11'
productVersion = '1.2.0.0'
setupMode = 'askTheUser'
setupLanguages = [
english: 'compiler:Default.isl',
spanish: 'compiler:Languages\\Spanish.isl'
]
disableRunAfterInstall = false
}
}

General properties​

PropertyDefaultDescription
icoFile${assetsDir}/windows/${name}.ico, or the default iconIcon of the EXE, Setup and MSI, in ICO format.
exeCreationToollaunch4jTool that builds the app EXE: launch4j, winrun4j or why. See EXE creation tools.
generateSetuptrueGenerates the Inno Setup installer ${name}_${version}.exe. Needs iscc.
generateMsitrueGenerates the MSI installer ${name}_${version}.msi. Needs WiX.
generateMsmfalseGenerates the MSI merge module ${name}_${version}.msm. It's also generated whenever generateMsi is true, because the MSI is built from it.
msiUpgradeCoderandom, on every buildUpgradeCode of the MSI. Set a fixed GUID so a new MSI upgrades the installed version.
signingCode signing configuration. See code signing.
registryRegistry values written by the installers. See Registry entries.

Installers can only be built on Windows; on other platforms they are skipped, unless forceInstaller is true.

EXE properties​

PropertyDefaultDescription
headerTypeguigui or console (a console window shows the app's output). Launch4j only.
wrapJartrueEmbeds the JAR in the EXE; if false, the JAR is copied next to it. Launch4j only.
vmLocationbin/client/jvm.dll or bin/server/jvm.dlljvm.dll path relative to the bundled JRE. WinRun4J only, with bundleJre.
companyNameorganizationNameCompany name in the EXE version info.
fileDescriptiondescriptionFile description in the EXE version info.
fileVersion1.0.0.0File version (x.x.x.x).
txtFileVersionversionFile version as text. Launch4j with Maven only.
productVersion1.0.0.0Product version (x.x.x.x). Also the MSI version: increase it for MSI upgrades.
txtProductVersionversionProduct version as text. Launch4j only.
productNamenameProduct name.
internalNamenameInternal name.
originalFilename${name}.exeOriginal file name. Not applied by Launch4j with Gradle.
copyrightorganizationNameCopyright. Launch4j only.
trademarksorganizationNameTrademarks. Launch4j only.
languageVersion info language, in Launch4j's format (e.g. ENGLISH_US). Launch4j only.

Setup properties​

PropertyDefaultDescription
setupModeinstallForAllUsersinstallForAllUsers, installForCurrentUser or askTheUser. See Setup modes.
setupLanguagesEnglish and SpanishMap of Inno Setup languages to .isl message files (several files separated by commas). Setting it replaces the default languages.
shortcutNamedisplayNameName of the desktop shortcut (Setup) and the Start menu shortcut (MSI).
createDesktopIconTasktrueSetup offers an optional "Create a desktop icon" task (unchecked by default).
disableDirPagetrueHides the Select Destination Location page.
disableProgramGroupPagetrueHides the Select Start Menu Folder page.
disableFinishedPagetrueHides the Setup Completed page.
disableWelcomePagetrueHides the Welcome page.
disableRunAfterInstalltrueIf false, Setup launches the app after installing it (not in silent installs).
removeOldLibsfalseDeletes the libs folder of a previous installation before installing, so old dependency JARs don't stay.

EXE creation tools​

Featurelaunch4j (default)winrun4jwhy
Builds on GNU/Linux and macOSYesNoNo
headerType (console or GUI)YesNoNo
wrapJarYesNo (JAR next to the EXE)No (JAR next to the EXE)
vmArgsYesYesNo: use a runtime options file
jreMinVersion (no bundled JRE)YesYesYes
Runtime options file (${name}.l4j.ini)YesNoYes
Administrator manifest, icon, version infoYesYesYes

All three embed a manifest that requests administrator privileges when administratorRequired is true.

  • Launch4j builds a 32-bit EXE, which runs a 64-bit JRE too. With Maven it runs launch4j-maven-plugin; with Gradle, the Launch4j Gradle library. VM arguments containing spaces are quoted.
  • WinRun4J uses a 32 or 64-bit launcher depending on arch, and reads its settings from ${name}.ini.
  • Why is a small native launcher; it reads launcher.ini and the runtime options file. You can replace the launcher with your own ${assetsDir}/windows/JavaLauncher.exe.
note

appArgs are not supported on Windows yet: they are ignored by the three tools.

With a bootstrap script, a ${name}.vbs script runs it and then the EXE, and it becomes the app's entry point in the installers.

Setup modes​

The Setup is built with Inno Setup. It installs the app in Program Files (for all users) or in %LOCALAPPDATA%\Programs (for the current user), adds a Start menu entry, registers the file associations, and can be uninstalled from the Windows settings. Its AppId is the app name, so a new Setup of the same app upgrades the installed one.

setupModeBehaviourOverride from the command line
installForAllUsersNeeds administrator privileges; installs for all users./CURRENTUSER installs for the current user
installForCurrentUserNo administrator privileges; installs for the current user./ALLUSERS installs for all users
askTheUserAsks the user./ALLUSERS or /CURRENTUSER

When the Setup launches the app after installing it, the app runs as the user who started the installer, not as the administrator who approved it, unless administratorRequired is true.

MSI and MSM​

The MSI and the MSM are built with WiX Toolset. If wix (WiX 4 or newer) is in the PATH it's used; otherwise JavaPackager uses candle and light (WiX 3).

The MSM (merge module) contains the whole app, a Start menu shortcut and the registry entries; you can merge it into your own MSI. The MSI installs that module for all users in Program Files (x64).

MSI upgrades

For a new MSI to upgrade an installed version, keep the same msiUpgradeCode in every release (by default it's a new random GUID on every build) and increase productVersion (it defaults to 1.0.0.0, it isn't taken from version). Downgrades and reinstalling the same version are refused.

The MSI doesn't create a desktop shortcut nor register file associations.

Registry entries​

registry adds values to the Windows Registry during installation.

FieldDefaultDescription
keyROOT:subkey, e.g. HKCU:Software\MyApp. Use \ as separator. Roots: HKCU, HKLM, HKCR, HKU (and HKCC, Setup only).
valueNameValue name; empty for the key's default value.
valueTypeREG_SZREG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ, REG_DWORD, REG_QWORD or REG_BINARY.
valueData""Value data.

On uninstall, the Setup removes the values it wrote; the MSI removes the whole key, including any other values in it.

This example adds a greeting string value with hello to HKEY_CURRENT_USER\Software\MyApp:

Maven
<registry>
<entries>
<entry>
<key>HKCU:Software\MyApp</key>
<valueName>greeting</valueName>
<valueType>REG_SZ</valueType>
<valueData>hello</valueData>
</entry>
</entries>
</registry>
Gradle
import io.github.javapackager.model.*

javapackager {
winConfig {
registry = new Registry([
new RegistryEntry('HKCU:Software\\MyApp', 'greeting', ValueType.REG_SZ, 'hello')
])
}
}