Migrating Ant builds to use the dita commandMigrating Ant buildsAlthough 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.AntexecAntdita-cmddita
command, benefits ofdita-cmddita commandmigrating Ant scriptsclasspathdita 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.
dita--input=sequence.ditamap--format= \
--propertyfile=properties/chm.propertiesdita--input=taskbook.ditamap--format= \
--propertyfile=properties/pdf.propertiesExample: Call the dita 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.