Running upgrade, migration and other routines using a properties file

Running upgrade, migration and other routines using a properties file

Ant supports passing property values into build scripts that can be used to tailor the behaviour of the tasks in the build script.

Properties take the form of “name=value”, and can be specified using one of two mechanisms:

  1. Via the command-line, using the -D switch.

  2. Using a properties file, whose location is specified on the command-line using the -propertyfile switch.

From the Ant manual the order of precedence is

-propertyfile <name> load all properties from file with -D properties taking precedence

This means that properties can be “mix and match” - properties can be specified via the -D switch, in a property file or both. Values may also be specified via a https://ant.apache.org/manual/Tasks/property.html in the build XML file.

To run an the default task in the setup.xml build script, using the smartdb, smartdbhost, smartdbport and other properties, values for these properties can provided in a properties file, as below.

Property file example

The name of the file may be anything, but build.properties is typical. The build file may contain many properties, and may also contain comments (via a line prefixed with the # character).

# Build properties for the setup.xml tasks # # SmartDB physical name (for -db), host (for -H) and port (for -S) smartdb=smartdb smartdbhost=localhost smartdbport=30002 # Location for the SmartComponentLibrary installation installroot=.. # Valid options: minimal/dependencies/full/none compile=full # Value for -assemblies, required for compile=dependencies or full assemblies=..\Assemblies

Command-line using property file

Assuming the above file is named build.properties , the command-line is:

%DLC%\ant\bin\ant \ -lib Install/PCT/PCT.jar \ -f setup.xml \ -propertyfile build.properties \ -Ddlc=%DLC%

Note that the value of the environment variable %DLC% is passed in to the build using a -D switch. Environment variables are not resolved in properties files.

Ant command without property file

The equivalent command using multiple -D switches is below. While the values passed to the bulid script are the same, the command-line is sginifacntly longer and contains no comments.

%DLC%\ant\bin\ant \ -lib Install/PCT/PCT.jar \ -f setup.xml \ -Dsmartdb="smartdb" \ -Dsmartdbhost="localhost" \ -Dsmartdbport="30002" \ -Ddlc=%DLC% \ -Dinstallroot=".." \ -Dcompile="full" \ -Dassemblies="..\Assemblies"