launch4j 2.1.5
Running launch4j
Configuration file
Importing 1.x configuration
Ant Task
Additional JVM options at runtime
Debug launching mode
Settings

Running launch4j

Run launch4j.exe or launch4j script without command line arguments to enter the GUI mode.
launch4j.exe
To wrap a jar in console mode use launch4jc.exe and specify the configuration file.
launch4jc.exe config.xml
On Linux use the launch4j script.
launch4j ./demo/l4j/config.xml

Configuration file

Launch4j requires an xml configuration file for each output executable. You can create and edit it conveniently using the graphic user interface or your favorite editor. Alternatively it's possible to pass all of the configuration parameters through the Ant task. All files except for <jre><path> may be absolute paths or relative to the configuration file path.
<!-- Bold elements are required -->
<launch4jConfig>
<!-- Header types: 0-GUI, 1-console -->
<headerType>0|1</headerType>
<outfile>file.exe</outfile>
<jar>file</jar>
<dontWrapJar>true|false</dontWrapJar>
<errTitle>text</errTitle>
<jarArgs>text</jarArgs>
<chdir>path</chdir>
<customProcName>true|false</customProcName>
<stayAlive>true|false</stayAlive>
<icon>file</icon>
<headerObjects>
<file>object file</file>
<file>object file</file>
...
</headerObjects>
<libs>
<file>w32api lib</file>
<file>w32api lib</file>
...
</libs>
<jre>
<!-- Specify one of the following or both -->
<path>path</path>
<minVersion>x.x.x[_xx]</minVersion>
<maxVersion>x.x.x[_xx]</maxVersion>
<!-- Heap sizes in MB, 0-use default -->
<initialHeapSize>MB</initialHeapSize>
<maxHeapSize>MB</maxHeapSize>
<args>text</args>
</jre>
<splash>
<file>file</file>
<waitForWindow>true|false</waitForWindow>
<timeout>seconds [60]</timeout>
<timeoutErr>true|false</timeoutErr>
</splash>
<versionInfo>
<fileVersion>x.x.x.x</fileVersion>
<txtFileVersion>text</txtFileVersion>
<fileDescription>text</fileDescription>
<copyright>text</copyright>
<productVersion>x.x.x.x</productVersion>
<txtProductVersion>text</txtProductVersion>
<productName>text</productName>
<companyName>text</companyName>
<internalName>filename</internalName>
<originalFilename>filename.exe</originalFilename>
</versionInfo>
</launch4jConfig>
<headerType>
Type of the header used to wrap the application.
Header type App type Launcher Splash screen Wait for the application to close
0 GUI javaw yes wrapper waits only if stayAlive is set to true, otherwise it terminates immediately or after closing the splash screen.
1 console java no always waits and returns application's exit code.
<outfile>
Output executable file.
<jar>
Depends on <dontWrapJar>, if false (the default) then this element is the executable jar to wrap. When <dontWrapJar> is set to true it's the runtime path of the jar relative to the executable. For example, if the executable launcher and the application jar named calc.exe and calc.jar are in the same directory then you would use <jar>calc.jar</jar>.
<dontWrapJar>
Optional, defaults to false. Launch4j by default wraps jars in native executables, you can prevent this by setting <dontWrapJar> to true. The exe acts then as a launcher and starts the application specified in <jar>
<errTitle>
Optional, sets the title of the error message box that's displayed if Java cannot be found for instance. This usually should contain the name of your application. The console header prefixes error messages with this property (myapp: error...)
<jarArgs>
Optional, constant command line arguments.
<chdir>
Optional. Change current directory to an arbitrary path relative to the executable. If you omit this property or leave it blank it will have no effect. Setting it to . will change the current dir to the same directory as the executable. .. will change it to the parent directory, and so on.
<chdir>.</chdir>
<chdir>../somedir</chdir>
<customProcName>
Optional, defaults to false. Set the process name as the executable filename. Creates a temporary file in launch4j-tmp directory inside the used JRE. These files are deleted by any launch4j wrapped application, which sets the process name and uses the same JRE. The removal takes place when the application starts, so at least one copy of this file will always be present.
<stayAlive>
Optional, defaults to false in GUI header, always true in console header. When enabled the launcher waits for the Java application to finish and returns it's exit code.
<icon>
Application icon in ICO format. May contain multiple color depths/resolutions.
<headerObjects>
Optional, custom headers only. Ordered list of header object files.
<libs>
Optional, custom headers only. Ordered list of libraries used by header.
<jre>
Required element that groups JRE settings.
<path>, <minVersion>, <maxVersion>
The <path> property is used to specify the absolute or relative path (to the executable) of an embedded JRE, it does not rely on the current directory or <chdir>. Note that this path is not checked until the actual application execution. If you'd like the wrapper to search for a JRE (public or SDK private) use the <minVersion> property, you may also specify the <maxVersion> to prevent it from using higher Java versions. Launch4j will always use the highest version available (in the min/max range of course). You can also combine these properties to change the startup process...
<path>
Run if bundled JRE and javaw.exe are present, otherwise stop with error.
<path> + <minVersion>  [+ <maxVersion>]
Use bundled JRE first, if it cannot be located search for Java, if that fails display error message and open the Java download page.
<minVersion>  [+ <maxVersion>]
Search for Java, if an appropriate version cannot be found display error message and open the Java download page.
<initialHeapSize>
Optional, initial heap size in MB, 0 - use default.
<maxHeapSize>
Optional, max heap size in MB, 0 - use default.
<args>
Optional, accepts everything you would normally pass to java/javaw launcher: assertion options, system properties and X options. Here you can map environment and special variables EXEDIR (exe's runtime directory), EXEFILE (exe's runtime full file path) to system properties. All variable references must be surrounded with percentage signs and quoted.
-Dlaunch4j.exedir="%EXEDIR%"
-Dlaunch4j.exefile="%EXEFILE%"
-Denv.path="%Path%"
-Dsettings="%HomeDrive%%HomePath%\\app-settings.ini"
<splash>
Optional, groups the splash screen settings. Allowed only in GUI header.
<file>
Splash screen image in BMP format.
<waitForWindow>
Optional, defaults to true. Close the splash screen when an application window or Java error message box appears. If set to false, the splash screen will be closed on timeout.
<timeout>
Optional, defaults to 60. Number of seconds after which the splash screen must be closed. Splash timeout may cause an error depending on <timeoutErr>.
<timeoutErr>
Optional, defaults to true. True signals an error on splash timeout, false closes the splash screen quietly.
<versionInfo>
Optional, version information to be displayed by the Windows Explorer.
<fileVersion>
Version number 'x.x.x.x'
<txtFileVersion>
Free form file version, for example '1.20.RC1'.
<fileDescription>
File description presented to the user.
<copyright>
Legal copyright.
<productVersion>
Version number 'x.x.x.x'
<txtProductVersion>
Free form file version, for example '1.20.RC1'.
<productName>
Text.
<companyName>
Optional text.
<internalName>
Internal name without extension, original filename or module name for example.
<originalFilename>
Original name of the file without the path. Allows to determine whether a file has been renamed by a user.

Importing 1.x configuration

It's possible to import a 1.x configuration file using the GUI interface. Open the file, correct the paths and save it as a new xml configuration.

Ant task

You may set a launch4j directory property or change the task definition.
<property name="launch4j.dir" location="/opt/launch4j" />
Define the task in your Ant build script.
<taskdef name="launch4j"
classname="net.sf.launch4j.ant.Launch4jTask"
classpath="${launch4j.dir}/launch4j.jar
:${launch4j.dir}/lib/xstream.jar" />
Execute the task!
<launch4j configFile="./l4j/demo.xml" />
You can set or override the following configuration properties...

jar="absolute path or relative to basedir"
jarPath="relative path"
outfile
fileVersion
txtFileVersion
productVersion
txtProductVersion

<launch4j configFile="./l4j/demo.xml"
outfile="mydemo.exe"
 fileVersion="1.0.0.0" txtFileVersion="1.0 RC2" />
You can also define the entire configuration in the task, but it will not be possible to edit such a file in the GUI mode. All paths except for <chdir>, <jre><path> and jarPath are calculated using the basedir project attribute.
<launch4j>
<config headerType="0" outfile="demo.exe"
dontWrapJar="true" jarPath="demo.jar" >
<jre minVersion="1.4.0" />
</config>
</launch4j>

Additional JVM options at runtime

When you create a wrapper or launcher all configuration details are compiled into the executable and cannot be changed without recreating it or hacking with a resource editor. Launch4j 2.1.2 introduces a new feature that allows to pass additional JVM options at runtime from an .ini file. Now you can specify the options in the configuration file, ini file or in both, but you cannot override them. The ini file's name must correspond to the executable's (myapp.exe : myapp.ini). The arguments should be separated with spaces or new lines, environment variable expansion is supported, for example:
-Dswing.aatext=true
-Dsomevar="%SOMEVAR%"
-Xms16m

Debug launching mode

To make sure the output executable is configured correctly you can use the debug launching mode which displays various information before starting the Java application. To enable it set the environment variable launch4j=debug and run the wrapped program. When using the GUI header redirect standard output to a file to see the results.
set launch4j=debug
app.exe >launch4j.log

Settings

Alternate bin directory: launch4j.bindir

It's possible to override the default bin directory location which contains windres and ld tools using the launch4j.bindir system property. The property can have two forms: a path relative to Launch4j's directory (altbin for example) or an absolute path.

Working directory: launch4j.tmpdir

Change the working directory if the default path contains spaces which windres cannot handle.