Variables - <variables>

Understanding Variables

This element allows you to define variables for the variables substitution system. Some variables are built-in, such as $INSTALL_PATH (which is the installation path chosen by the user).

To define a set of variables, you place as many <variable> elements as needed inside a <variables> or <dynamicvariables> element which are in turn children of the <installation> element.

If you define a variable named VERSION you need to type $VERSION in the files to parse. The variable substitutor will then replace it with the correct value.

Each <variable> tag take the following attributes :

Here's a sample <variables> section :

 

<variables>
  <variable name="app-version" value="1.4"/>
  <variable name="released-on" value="08/03/2002"/>
</variables>

Types of Variables

Static variables

Static variables can be defined by the user using the <variables> element.
They are evaluated on launching an installation and won't alter during the installation process. Static variables can assigned from an system environment variable on launching an IzPack installations.

Environment variables

Environment variables can be accessed using the syntax ${ENV[variable]}. The curly braces are mandatory. Note that variable names are case-sensitive and usually in UPPER CASE. For example, to get the value of the OS environment variable ANT_HOME, use ${ENV[ANT_HOME]} in the resource you want to substitute the according value during an installation.

Dynamic variables

Dynamic variables can be defined by the user using the <dynamicvariables> element in the installation description.
Dynamic variables are the most powerful facility of saving and gathering values on a target system where the installation is launched. The value of dynamic variables will be evaluated every time a panel is switched. Furthermore, beginning with IzPack 5.0, dynamic variables can be also assigned from several configuration and archive files, the Windows registry, the output of a command execution and dynamically filtered using Java regular expressions. See Dynamic Variables for more information and some examples how this can be achieved.
Dynamic variables can be handled like other variable types for variable substitution.

See Dynamic Variables for more details.

Built-In variables

There is a couple of "hard-coded" variables implemented in IzPack. The value of several built-in variables might alter depending on local conditions on the target system where the installation is launched.

The following variables are built-in :

Variable Substitution

References to variables enclosed in certain placeholder begin and end marks (for example ${ and }) can be used to substitute the specified placeholders in

Substitute Variables in the Installer Descriptor

In additional to properties, static variables defined by the <variables> tag can be substituted in the installer descriptor (install.xml) itself, where they have been defined.

This is limited to static and built-in variables. It is not possible to substitute dynamic variables here, because they are refreshed and evaluated during the installation as soon as a panel is activated or changed, not at compilation time.

Variable references in the installer descriptor apply on the plain style syntax, with a leading $ before the variable name, optionally enclosed in curly braces. Example ${MY_VAR} or $MY_VAR.

Substitute Variables in Resource Files

Variables can be also substituted in resource files declared by the <resources> tag.

This is limited to static and built-in variables. It is not possible to substitute dynamic variables here, because they are refreshed and evaluated during the installation as soon as a panel is activated or changed, not at compilation time, and resource files are static files.

Variable references in the installer descriptor apply on the plain style syntax, with a leading $ before the variable name, optionally enclosed in curly braces. Example ${MY_VAR} or $MY_VAR.

Substitute Variables in Installed Files

To replace variable references in installed textfiles those files must be tagged as parsable.

For this purpose, specify the <parsable> tag on a file. Files marked parsable are parsed during the installation on the fly, references to existing variables are substituted, and the file is saved with substituted variable values.

See the <packs> element documentation for more information on how to use the <parsable> tag.

Using System Properties As Variables

System properties are directly assigned to variables using the following syntax, provided the system property is variable.name:


IzPack 5.0 and later:

${SYSTEM[variable.name]}

More examples, provided -Dfeature.Enabled=true is added to launching the installer on the command line:

<variables>
  <variable name="featureEnabled" value="${SYSTEM[feature.Enabled]}" />
</variables>

<conditions>
  <condition type="variable" id="isFeatureEnabled">
    <name>featureEnabled</name>
    <value>true</value>
  </condition>
</conditions>

 is equivalent to:

<conditions>
  <condition type="variable" id="isFeatureEnabled">
    <name>SYSTEM[feature.Enabled]</name>
    <value>true</value>
  </condition>
</conditions>


IzPack 4 and earlier (obsolete handling in IzPack 5.0 for backward compatibility):


${SYSTEM_variable_name}

If the variable name contains '.' characters they got to be replaced by '_' here.

More examples, provided -Dfeature.Enabled=true is added to launching the installer on the command line:

<variables>
  <variable name="featureEnabled" value="${SYSTEM_feature_Enabled}" />
</variables>

<conditions>
  <condition type="variable" id="isFeatureEnabled">
    <name>featureEnabled</name>
    <value>true</value>
  </condition>
</conditions>

 is equivalent to:

<conditions>
  <condition type="variable" id="isFeatureEnabled">
    <name>SYSTEM_feature_Enabled</name>
    <value>true</value>
  </condition>
</conditions>

For Izpack before 5.0.0-rc2, no real substitution on demand happens but all system properties known to the JVM are added as IzPack variables by default when the installer starts.