Skip to main content

Templates

Many files JavaPackager generates (the GNU/Linux startup script, the macOS Info.plist, the Inno Setup and WiX scripts...) come from Apache Velocity templates. You can replace any of them with your own.

Overriding a template​

Put a template with the same path in your assetsDir. For example, assets/windows/iss.vtl replaces the built-in Inno Setup script. JavaPackager looks in assetsDir first and falls back to its own templates.

Start from a copy of the built-in template of the version you use, and change only what you need.

caution

Your templates replace whole files, so they don't get the fixes of newer JavaPackager versions. Check them when upgrading.

Built-in templates​

TemplateGeneratesWhen
linux/startup.sh.vtlThe app's startup scriptAlways
linux/desktop.vtlThe desktop entryAlways
linux/desktop-appimage.vtlThe AppImage desktop entryAppImage
linux/mime.xml.vtlThe MIME types fileWith file associations
linux/control.vtlThe DEB control fileDEB
linux/assembly.xml.vtlThe zipball and tarball layoutMaven bundles
mac/Info.plist.vtlThe app's Info.plistUnless customInfoPlist
mac/RuntimeInfo.plist.vtlThe bundled JRE's Info.plistWith bundleJre, unless customRuntimeInfoPlist
mac/startup.vtlThe script that asks for an administrator passwordWith administratorRequired
mac/entitlements.plist.vtlThe default entitlementsSigning without entitlements
mac/customize-dmg.applescript.vtlThe DMG window layoutDMG
mac/assembly.xml.vtlThe zipball and tarball layoutMaven bundles
windows/exe.manifest.vtlThe EXE manifest (administrator privileges)Always
windows/ini.vtlThe WinRun4J settingsexeCreationTool is winrun4j
windows/why-ini.vtlThe Why launcher settingsexeCreationTool is why
windows/startup.vbs.vtlThe script that runs the bootstrap scriptWith a bootstrap script
windows/iss.vtlThe Inno Setup scriptSetup
windows/wxs.vtlThe WiX source of the MSIMSI
windows/msm.wxs.vtlThe WiX source of the MSMMSM
windows/assembly.xml.vtlThe zipball and tarball layoutMaven bundles

Variables​

Templates can use these variables:

VariableValue
$infoThe packager, with every configuration property ($info.name, $info.version, $info.winConfig.productVersion...) and runtime values such as $info.appFolder, $info.jarFile, $info.executable or $info.iconFile.
$StringUtilsApache Commons Lang's StringUtils, e.g. $StringUtils.capitalize($info.name).
$GUIDJava's UUID class, e.g. $GUID.randomUUID().

Your own values​

To pass your own values to your templates, use the extra map:

Maven
<extra>
<supportEmail>support@example.com</supportEmail>
</extra>
Gradle
javapackager {
extra = [ supportEmail: 'support@example.com' ]
}

And use them in a template as $info.extra.supportEmail or ${info.extra["supportEmail"]}.

Byte order mark​

Generated files are UTF-8, without a byte order mark (BOM), except the Inno Setup script, which needs one. The templates property changes it per template:

Maven
<templates>
<template>
<name>windows/iss.vtl</name>
<bom>false</bom>
</template>
</templates>
Gradle
javapackager {
templates = [ new io.github.javapackager.model.Template('windows/iss.vtl', false) ]
}

Velocity and shell scripts​

Velocity reads ${name[@]} (Bash array expansion) as its own syntax and fails. In shell templates, wrap such lines in an unparsed block, which Velocity copies as is:

#[[
"${JVMDefaultOptions[@]}"
]]#