Exe4J Manual: © 2017 Ej-Technologies Gmbh. All Rights Reserved
Exe4J Manual: © 2017 Ej-Technologies Gmbh. All Rights Reserved
Licensing ................................................................................................................................................ 4
• To get an overview of exe4j's features, please have a look at the sample projects in the demo
directory of your exe4j installation.
• When starting exe4j, a wizard [p. 5] will guide you step by step through collecting the
necessary information to create your executable.
• A command line compiler [p. 22] is available to facilitate the inclusion of exe4j into an
automated build process like ant [p. 23] .
3
Exe4j Licensing
Without a valid license, exe4j may be used for evaluation purposes only. The evaluation period
is not time limited, but excludes any use for creating distributions of commercial products.
exe4j licenses can be purchased easily and securely online. We accept a large variety of payment
methods including credit cards, checks and purchase orders. Pricing information is available
online.
You can enter your license key in the welcome step [p. 6] of the exe4j wizard. If a license has
been entered, the licensing information is visible there. The exe4j command line compiler [p.
22] also prints licensing information except when invoked with the quiet option [p. 22] .
Please read the included file license.txt to learn more about the scope of the license. For
licensing questions, please contact [email protected].
License key dialog:
Together with your license key, you are asked for your name and - if applicable - for the name
of your company.
To make it easier for you to enter the license key, you can use the [Paste from clipboard] button,
after copying any text fragment which contains the license key to your system clipboard. If a
valid license key can be found in the clipboard content, it is extracted and displayed in the dialog.
4
A Exe4j Wizard
• (1) Index
The index of steps lists all steps of the wizard and highlights the current step in bold face. You
can click on any step in the index to arbitrarily move between wizard steps. Alternatively, you
can use the navigation controls (see below).
• (2) Current step
The information for the current step is entered here. See the help pages for each step [p. 5]
for specific information.
• (3) Navigation
The navigation bar allows you to move back and forward through the steps of the wizard with
the [Next] and [Previous] buttons. The [Finish] button allows you to complete the wizard
immediately without moving through the remaining steps. Should any required information
be missing, the wizard will alert you to it. The [Help] button shows context specific help that
is also available by pressing F1. With the [Cancel] button you can leave the wizard at any time.
Should you have made modifications to the configuration, you will be asked whether you want
to save your changes before the wizard exits.
5
By default, the wizard starts with a template config file that contains default values where
appropriate. The template config file is loaded from config\template.exe4j in the exe4j
installation directory.
If you would like to load a config file at startup, you can pass the path of the desired config file
to the wizard executable (bin\exe4j.exe in the exe4j installation directory).
License information is displayed at the bottom and can be entered or changed [p. 4] by clicking
the [Enter license] or [Change license] buttons.
6
• Regular Mode
Enter the distribution source directory in the Directories section of this step. The
distribution source directory is the topmost directory under which all other directories of your
application reside. Many directories and file paths that are referenced by the executable need
to be known as relative rather than absolute paths. If you select such directories and files in
later steps by means of a file chooser, the paths will be converted to paths relative to the
distribution source directory.
Enter the executable directory in the Directories section of this step. The executable
directory is the directory below the distribution source directory where the executable is to
be placed. You can leave the output directory empty (or enter a ".") to make it equal to the
distribution source directory. If you choose a directory with the file chooser (by clicking the
[...] button), the directory will be converted into a path relative to the distribution source
directory.
• Jar-in-Exe Mode
Enter the output directory to determine where exe4j should place the generated application.
• Executable type
Executables created by exe4j can be either GUI or console applications:
• GUI application
There is no terminal window associated with a GUI application. If stdout and stderr are not
redirected (see the redirection advanced step [p. 12] ), both streams are inaccessible for
the user. This corresponds to the behavior of javaw.exe.
If you launch the executable from a console window, a GUI application can neither write to
or read from that console window. Sometimes it might be useful to use the console, for
example for seeing debug output or for simulating a console mode with the same executable.
In this case you can select the Allow -console parameter check box. If the user supplies
the -console parameter when starting the launcher from a console window, the launcher
will try to acquire the console window and redirect stdout and stderr to it. If you redirect
stderr and stdout in the redirection settings [p. 12] , that output will not be written to the
console.
• Console application
A console application has an associated terminal window. If a console application is opened
from the Windows explorer, a new terminal window is opened. If stdout and stderr are not
redirected (see the redirection advanced step [p. 12] ), both streams are printed on the
terminal window. This corresponds to the behavior of java.exe.
• Service
A Windows service runs independently of logged in users and can be run even if no user is
logged on. The main method will be called when the service is started.
To handle the shutdown of the service, you can use the Runtime.addShutdownHook()
method to register a thread that will be executed before the JVM is terminated.
7
For information on how services are installed or uninstalled, please see the help on service
start options [p. 13] .
• Executable name
Enter the desired name of the executable without the trailing .exe.
• Icon file
If you would like a custom icon to be compiled into your executable, select the Icon file
checkbox and choose an icon file (extension *.ico).
• Working directory
For some applications (especially GUI applications) you might want to change the working
directory to a specific directory relative to the executable, for example to read config files that
are in a fixed location. To do so, please select the Change working directory to: checkbox
and enter a directory relative to the executable in the adjacent text field. To change the current
directory to the same directory where the executable is located, please enter a single dot.
• Allow only a single running instance of the application
If you select this checkbox, the generated exe4j executable can only be started once.
Subsequent user invocations will bring the application to the front. In the Controller class
of the exe4j launcher API you can register a startup handler to receive the command line
parameters. In this way, you can handle file associations with a single application instance.
• Fail if an exception in the main thread is thrown
Executables created by exe4j can monitor whether the main method throws an exception and
show an error dialog in that case. This provides a generic startup error notification facility for
the developer that handles a range of errors that would otherwise not be notified correctly.
For example, if an uncaught exception is thrown during application startup, a GUI application
might simply hang, leaving the user in the dark about the reasons for the malfunction. With
the error message provided by the exe4j executable, reasons for startup errors are found
much more easily.
• Main class
Enter the fully qualified main class of your application. Next to the text field is a [...] chooser
button that brings up a dialog with a list of all public main classes [p. 18] in the class path. To
use this facility, you have to set up your classpath first (see below).
• VM parameters
If there are any VM parameters you would like to specify for the invocation of your Java
application, you can enter them here (e.g. -Dmyapp.myproperty=true or -Xmx256m).
There are several runtime-variables you can use to specify runtime directories:
• %EXE4J_EXEDIR%
This is the directory where the executable is located.
• %EXE4J_JVM_HOME%
This is the directory of the JRE that your executable is running with.
8
• %EXE4J_TEMPDIR%
For the "JAR in EXE" mode [p. 6] , this variable will contain the location of the temporary
directory for the JAR files. In "regular mode" [p. 6] this variable is not used.
These variables can be especially useful for adding JAR files to the bootclasspath.
exe4j has the ability to add specific VM parameters depending on the Java version. To set this
up, click on the [Configure version specific VM parameters] button. In the dialog, add rows
for each Java version that should receive specific VM parameters. The comparison checks if
the Java version string starts with the specified characters, so "1.8" will match "1.8.0_60", for
example. These VM parameters are added after the common VM parameters so you can use
them to override common settings.
In addition to these VM parameters, a parameter file in the same directory as the executable
is read and its contents are added to the existing VM parameters. The name of this parameter
file is the same as the exe file with the extension *.vmoptions. For example, if your exe file
is named hello.exe, the name of the VM parameter file is hello.vmoptions. In this file,
each line is interpreted as a single VM parameter. For example, the contents of the VM
parameter file could be:
-Xmx128m
-Xms32m
It is possible to include other .vmoptions files from a .vmoptions file with the syntax
-include-options [path to other .vmoptions file]
You can use multiple includes in a single file, recursive includes are also supported. You can
also add this option to the fixed VM parameters. In that way, you can prevent having to use
the .vmoptions file right next to the executable.
This allows you to to centralize the user-editable VM options for multiple launchers and to
have .vmoptions files in a location that can be edited by the user if the installation directory
is not writable. You can use environment variables to find a suitable directory, for example
-include-options ${APPDATA}\My Application\my.vmoptions
or
-include-options ${USERPROFILE}\.myapp\my.vmoptions
In addition to the VM parameters you can also modify the classpath in the .vmoptions files
with the following options:
• -classpath [classpath]
Replace the classpath of the generated launcher.
• -classpath/a [classpath]
Append to the classpath of the generated launcher.
• -classpath/p [classpath]
Prepend to the classpath of the generated launcher.
You can use environment variables in the VM parameters with the following syntax:
${VARIABLE_NAME} where you replace VARIABLE_NAME with the desired environment
variable.
• arguments
If you need to specify arguments for your main class, you can enter them here. Arguments
passed to the executable will be appended to these arguments.
9
• Allow VM passthrough parameters
If you would like to allow the user to specify VM parameters with the syntax -J[VM
parameter] (e.g. -J-Xmx512m), select the Allow VM passthrough parameters checkbox.
In the Class path section of this step you can configure the class path and the error handling
for missing class path entries. The class path list shows all class path entries that have been
added so far. The following types of class path entries [p. 18] are available:
• Scan directory
• Directory
• Archive
• Environment variable
The symbol prepended to an entry indicates that an error with that entry will lead to a startup
failure with an error message displayed to the user. The control buttons on the right allow you
to modify the contents of the class path list:
Invokes the class path entry dialog [p. 18] . Upon closing the class path entry dialog with the
[OK] button, a new class path entry will be appended to the bottom of the class path list.
• Remove class path entry (key DEL)
Removes the currently selected class path entry without further confirmation.
• Move class path entry up (key ALT-UP)
Moves the selected class path entry up one position in the class path list.
• Move class path entry down (key ALT-DOWN)
Moves the selected class path entry down one position in the class path list.
To change the error handling mode of a class path entry [p. 18] , select the class path entry and
press [Toggle 'fail on error'] right below the class path list or choose the corresponding menu
item from the context menu.
10
In addition to the version requirements, the following constraints are available:
For more detailed requirements on which JRE should be used (e.g. for bundling your own JRE in
the distribution), please see the search sequence advanced options step [p. 16] and the preferred
VM advanced options step [p. 17] .
11
• Reset column
If a message has been customized, the last column displays a [Reset] button. Clicking on that
button will change the message text back to the default text.
The context menu of the message table allows you to edit the selected message, reset it to the
default text (if applicable) or reset all messages to the default text (if applicable).
• Redirection of stderr
To redirect stderr to a file, select the Redirect stderr checkbox and enter a file name in
the adjacent text field.
• Redirection of stdout
To redirect stdout to a file, select the Redirect stdout checkbox and enter a file name in
the adjacent text field.
File name are interpreted relative to the executable. Enter /dev/null if you want to suppress
output completely. You can choose whether the redirection file is overwritten each time the
launcher is started or if output should be appended to an existing redirection file.
12
Note that redirection files are created lazily. This means that if nothing is written to the redirected
stream, the file file will not be created or overwritten.
You can use environment variables in the redirection files with the following syntax:
${VARIABLE_NAME} where you replace VARIABLE_NAME with the desired environment variable.
• start on demand
In start on demand mode, your service must be manually started by the user in the Windows
service manager. Use this option, if you're not sure if your users will actually want to run your
application as a service, but you want to give them an easy way to do so. This installation
mode can be forced if the user passes /install-demand to the generated executable instead
of /install.
• auto start
In auto start mode, your service is always started when Windows is booted. This installation
mode can be forced if the user passes /install-auto to the generated executable instead
of /install.
Windows services are always uninstalled by passing /uninstall to the generated service
executable. All command line switches also work with a prefixed dash instead of a slash (like
-uninstall) or two prefixed dashes (like --uninstall).
To start or stop the service, the /start, /stop and /restart options are available. In addition,
a /status argument shows if the service is already running. The exit code of the status command
is 0 when the service is running, 3 when it is not running and 1 when the state cannot be
determined (for example when it is not installed).
As a second parameter after the /install parameter, you can optionally pass a service name.
In that way you can
• install a service with a different service name than the default name.
• Use the same service executable to start multiple services with different names. To distinguish
several running service instances at runtime, you can query the system property
exe4j.launchName for the service name. Note that you also have to pass the same service
name as the second parameter if you use the /uninstall, /start and /stop parameters.
For debugging purposes, you may want to run the executable on the command line without
starting it as a service. This can be done with the /run parameter. In that case, all output will be
printed on the console. If you want to keep the redirection settings, use the /run-redirect
parameter instead.
If your service depends on another service, say a database, you can enter the service name of
the other service in the dependencies text field. You do not have to enter core OS services such
as filesystem or network, these services will always be initialized before your service is launched.
13
If you have dependencies on multiple services, you can enter a list of these service names
separated by commas.
• Product version
The product version must be composed of a maximum of 4 numbers, separated by spaces,
commas or dots. By using the -r flag for the command line compiler [p. 22] , the product
version can be overidden. The product version is also used in the splash screen version line
config [p. 11] as a replacement value for the variable %VERSION%.
• File version
If you want to specify a version for the file which is a different from the product version, you
can do it here. If this field is left empty, the product version will be used for the file version.
• Internal name
Choose a short internal name for identifying your application.
• Company name
Enter the name of your company.
• File description
Enter a description of the application.
• Legal copyright
Enter a copyright statement for your application.
14
On a 64-bit Windows, there are separate system directories for 32-bit and 64-bit applications. If
you enable the 64-bit executable mode in this step, those system directories will be appropriate
for 64-bit applications, e.g. c:\Program Files instead of c:\Program Files (x86).
• As invoker
This is the default setting. The executable will be executed with the rights of the current token.
If the user is an Administrator, this will be a filtered token so the executable will not have all
administration rights.
• Highest available
This level will raise the rights of the executable to the maximum extend available for the
current user. This applies to Administrators that usually run with a filtered token. Windows
Vista and higher will show a question to the user if he wants to elevate the rights of this
application. For a standard user this is the same as "As invoker".
• Require administrator
This is the same as "Highest available" when the user is an Administrator running with a filtered
token. If the user is a standard user, Windows Vista and higher will ask for the credentials of
an Administrator account.
The user can set the Windows DPI setting to a value that is larger than 100%. This is particularly
relevant for high-resolution screens.
If your application can deal with different DPI settings, you can tell exe4j to add the manifest
entry to the executable that enables DPI-awareness. If this option is not selected, the GUI will
be scaled up automatically and may look somewhat blurry.
Lets you add a new directory to the end of the list. Choose the native library directory in the
file chooser that appears after clicking this button. The directory will be converted to a path
relative to the distribution source directory.
• Remove native library directory (key DEL)
Removes the currently selected native library directory entry without further confirmation.
• Move entry up (key ALT-UP)
Moves the selected native library directory entry up one position in the path list.
• Move entry down (key ALT-DOWN)
15
Moves the selected native library directory entry down one position in the path list.
• Search registry
• Directory
• Environment variable
The control buttons on the right allow you to modify the contents of the search sequence list:
Invokes the search sequence entry dialog [p. 19] . Upon closing the search sequence entry
dialog with the [OK] button, a new search sequence entry will be appended to the bottom of
the search sequence list.
• Remove search sequence entry (key DEL)
Removes the currently selected search sequence entry without further confirmation.
• Move search sequence entry up (key ALT-UP)
Moves the selected search sequence entry up one position in the class path list.
• Move search sequence entry down (key ALT-DOWN)
Moves the selected search sequence entry down one position in the class path list.
It is possible to generate a log file that contains information about the JRE search sequence and
any potential problems. In order to switch on logging, please define the environment variable
EXE4J_LOG=yes and look for the newest text file whose name starts with i4j_nlog_ in the
Windows temp directory. This information can be used for debugging purposes. If you have a
problem with JRE detection, please send this log file along with your support request.
An easier way for a user to create a log file is to start the launcher with the /create-i4j-log
argument. The launcher will notify the user where the log is created and will offer to open an
explorer window with the log file selected. After the message box, the launcher will continue to
start up.
Tip: To distribute your own JRE, simply put the JRE in your distribution and define a directory
search sequence entry with the appropriate relative path (e.g. jre) as the first item.
If the entire search sequence fails, exe4j will try the location defined by the environment variable
EXE4J_JAVA_HOME. If that fails too, an error message will be displayed asking the user to define
this variable. To supply a custom variable, define an appropriate environment variable search
16
sequence entry and customize the corresponding error message in the messages step [p. 11]
of the wizard.
• default VM
exe4j will use the default VM for the found JRE.
• client hotspot VM
exe4j will try to use the client hotspot VM for the found JRE. This is equivalent to using the
-client switch when invoking java from the command line.
• server hotspot VM
exe4j will try to use the server hotspot VM for the found JRE. This is equivalent to using the
-server switch when invoking java from the command line.
Please note that it is not an error if the selected JVM is not present for the found JRE. exe4j will
simply use another JVM to launch your application in that case.
• Text
The (initial) text displayed in the text line.
• Position
The x and y-coordinates of the text line on the splash screen. The origin of the coordinate
system is the top left corner of the splash screen window.
• Font
The font used for drawing the text line:
17
• Size
The size of the font in points.
• Bold
Whether the font weight should be bold or not.
• Color
The color of the font. By clicking on [...], a color chooser dialog is brought up.
To visually position the text lines with mouse and keyboard on the actual splash screen image,
please click on the [Position text lines visually] button. The visual positioning dialog [p. 20]
will then be displayed. On exiting the dialog with the [OK] button, the X/Y coordinate text fields
(see above) will be updated for both text lines.
A.13 Dialogs
A.13.1 Main Class Selection Dialog
The main class selection dialog is shown when clicking on the [...] chooser button next to the
main class text field in the Java invocation step [p. 8] .
Please choose a main class from the list and click on [OK] or double-click on the selected class.
If you do not want to make a choice, please click on [Cancel].
The class path entry dialog is shown when clicking on the add button in the "configure java
invocation" step [p. 8] of the exe4j wizard. Upon closing this dialog with the [OK] button, a new
class path entry will be appended to the bottom of the class path list of that step.
To define a class path entry, you first select the entry type, then check the fail if an error
occurs with this class path entry checkbox in case you want the startup to be terminated
if this class path entry is faulty and finally fill out the Detail section of the dialog which is
dependent on the selected entry type. The following entry types are available:
• Scan directory
Scan a directory for archives with the extensions *.jar and *.zip to be added to the class
path. In the Detail section of the dialog you must choose a directory either by entering the
path in the text field or by clicking [...] and choosing it with a file chooser.
Error handling:
If fail if an error occurs with this class path entry is checked, the application
will terminate with an error message if this directory does not exist.
Note: Not available if the project type [p. 6] is "JAR in EXE"
• Directory
Add a directory to the class path. In the Detail section of the dialog you must choose a
directory either by entering the path in the text field or by clicking [...] and choosing it with a
file chooser.
Error handling:
18
If fail if an error occurs with this class path entry is checked, the application
will terminate with an error message if this directory does not exist.
Note: Not available if the project type [p. 6] is "JAR in EXE"
• Archive
Add an archive with the extension *.jar or *.zip to the class path. In the Detail section
of the dialog you must choose an archive either by entering the path in the text field or by
clicking [...] and choosing it with a file chooser.
The last path component can include a * as a placeholder for a frequently changing version
number. This is not a wildcard for processing multiple matching paths, rather it is intended
for systems like maven where the version number on dependencies is part of the file name
and is frequently changed. An example is bin\commons-io-*.jar which will match a file
like bin/commons-io-1.0.jar at compile time. This replacement is performed at
compile-time and not a runtime.
Error handling:
If fail if an error occurs with this class path entry is checked, the application
will terminate with an error message if this archive does not exist.
• Environment variable
Add the contents of an environment variable to the class path. In the Detail section of the
dialog you must enter the name of an environment variable.
Error handling:
If fail if an error occurs with this class path entry is checked, the application
will terminate with an error message if this environment variable is not defined.
Except for the "Environment variable" classpath type, you can use environment variables in the
text field with the following syntax: ${VARIABLE_NAME} where you replace VARIABLE_NAME
with the desired environment variable.
The directory of the JRE that your application is running with is contained in ${EXE4J_JVM_HOME}.
If you've specified in the Configure JRE step [p. 10] , that only JDKs and no JREs should be used,
you can append \.. after the variable to change into the JDK home directory. For example, to
reference tools.jar, you'd have to write %EXE4J_JVM_HOME%\..\lib\tools.jar.
Note that for path selections by means of a file chooser ([...] buttons), exe4j will try to convert
the path to be relative to the distribution source directory.
The search sequence entry dialog is shown when clicking on the add button in the "configure
search sequence" step [p. 16] of the exe4j wizard. Upon closing this dialog with the [OK] button,
a new search sequence entry will be appended to the bottom of the search sequence list of that
step.
To define a search sequence entry, you select the entry type and fill out the Detail section of
the dialog which is dependent on the selected entry type. The following entry types are available:
• Search registry
Search the Windows registry for installed JREs and JDKs by Sun Microsystems.
• Directory
19
Look in the specified directory. This is especially useful if you distribute your own JRE along
with your application. In that case, be sure to supply a relative path. Note that for path
selections by means of the file chooser ([...] button), exe4j will try to convert the path to be
relative to the distribution source directory.
• Environment variable
Look for a JRE of JDK in a location that is defined by an environment variable like JAVA_HOME
or MYAPP_JAVA_HOME.
20
B Exe4j Launcher API
The launcher API of exe4j is contained in exe4jlib.jar which can be found in the top level
directory of your exe4j installation.
Note: you do not have to add it to the classpath of your application and distribute it along with
it, since that file is always contained in the executable.
21
C Exe4j Command Line Compiler
The available options are described here [p. 22] . A quick help for all options is printed to the
terminal when invoking
exe4jc --help
A typical run of the exe4j command line compiler looks like this:
exe4j version 4.0, built on 2006-09-26
Unregistered evaluation version
In order to facilitate the use of exe4j in automated build processes, the destination directory for
the executable and the version text line of the splash screen [p. 11] can be overridden with
command line options [p. 22] . Since the file format of exe4j's config files is xml-based, you can
achieve arbitrary customizations by replacing tokens (see the ant integration help page [p. 23]
for an example) or by applying XSLT stylesheets to the config file.
• -h or --help
Displays a quick help for all available options.
• -V or --version
Displays the version of exe4j in the following format:
exe4j version 1.0, built on 2002-10-05
• -v or --verbose
Enables verbose mode. In verbose mode, exe4j prints out information about internal processes.
If you experience problems with exe4j, please make sure to include the verbose terminal
output with your bug report.
• -q or --quiet
Enables quiet mode. In quiet mode, no terminal output short of a fatal error will be printed.
• -t or --test
Enables test mode. In test mode, no executable will be generated in the directory for the
executable.
• -L or --license=KEY
Update the license key on the command line. This is useful if you have installed exe4j on a
headless system and cannot start the GUI. KEY must be replaced with your license key.
22
• -x or --require-license
By default, exe4j will fallback to evaluation mode if the license key is not valid. If you want the
compilation to fail instead, you can spcify this option.
• -r STRING or --release=STRING
override the application version defined in the version info step [p. 14] . STRING must be
replaced with the desired version number. The version number can only contain numbers
and dots.
• -d STRING or --destination=STRING
override the destination directory for the executable. STRING must be replaced with the
desired directory. If the directory contains spaces, you must enclose STRING in quotation
marks.
Note that this option does not affect the interpretation of relative paths defined by the
distribution source directory and the output directory as specified in the application step [p.
6] of the exe4j wizard.
<target name="launcher">
<exe4j projectfile="myapp.exe4j"/>
</target>
The taskdef definition must occur only once per ant-build file and can appear anywhere on the
top level below the project element.
Note: it is not possible to copy the ant.jar archive to the lib folder of your ant distribution.
You have to reference a full installation of exe4j in the task definition.
The exe4j task supports the following parameters:
projectfile The exe4j config file for the launcher that should Yes
be generated.
23
Attribute Description Required
To customize aspects of the exe4j build that cannot be overridden with he above parameters,
you can add appropriate tokens in the config file and use the copy task with a nested filterset
element. For example, if the main class in
<java mainClass="com.mycorp.MyApp" ...
24