Migrating Ant builds to use the <cmdname>dita</cmdname> command Migrating Ant builds Although DITA Open Toolkit still supports Ant builds, switching to the dita command offers a simpler command interface, sets all required environment variables and allows you to run DITA-OT without setting up anything beforehand. Antexec Antdita-cmddita command, benefits of dita-cmd dita commandmigrating Ant scripts classpathdita command

Building output with the dita command is often easier than using Ant. In particular, you can use .properties files to specify sets of DITA-OT parameters for each build.

You can include the dita command in shell scripts to perform multiple builds.

In your Ant build file, identify the properties set in each build target. Some build parameters might be specified as properties of the project as a whole. You can refer to a build log to see a list of all properties that were set for the build. Create a .properties file for each build and specify the needed build parameters, one per line, in the format name = value. Use the dita command to perform each build, referencing your .properties with the --propertyfile=file option. Example: Ant build

Prior to DITA-OT 2.0, an Ant build like this was typically used to define the properties for each target.

Sample build file: dita-ot-dir/docsrc/samples/ant_sample/build-chm-pdf.xml

Example: <filepath>.properties</filepath> files with <cmdname>dita</cmdname> command

The following .properties files and dita commands are equivalent to the example Ant build.

Sample .properties file: /properties/chm.properties

Sample .properties file: /properties/pdf.properties

Run from :

dita --input=sequence.ditamap --format= \ --propertyfile=properties/chm.properties dita --input=taskbook.ditamap --format= \ --propertyfile=properties/pdf.properties
Example: Call the <cmdname>dita</cmdname> command from an Ant build

In some cases, you might still want to use an Ant build to implement some pre- or post-processing steps, but also want the convenience of using the dita command with .properties files to define the parameters for each build. This can be accomplished with Ant’s exec task.

This example uses a dita-cmd Ant macro defined in the /ant_sample/dita-cmd.xml file:

You can use this macro in your Ant build to call the dita command and pass the input, format and propertyfile parameters as follows: <dita-cmd input="sample.ditamap" format="pdf" propertyfile="sample.properties"/>

This approach allows you to use Ant builds to perform additional tasks at build time while allowing the dita command to set the classpath and ensure that all necessary JAR libraries are available.

The attributes defined in the Ant macro are required and must be supplied each time the task is run. To set optional parameters in one build (but not another), use different .properties files for each build.

Sample build file: /ant_sample/build-chm-pdf-hybrid.xml