migrating-ant-to-dita.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!DOCTYPE html
  2. SYSTEM "about:legacy-compat">
  3. <html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="UTF-8"><meta name="copyright" content="(C) Copyright 2018"><meta name="DC.rights.owner" content="(C) Copyright 2018"><meta name="DC.Type" content="task"><meta name="description" content="Although Ant builds are still supported in the DITA Open Toolkit, you might want to switch to use the new dita command."><meta name="DC.Relation" scheme="URI" content="../topics/build-using-dita-command.html"><meta name="DC.Format" content="HTML5"><meta name="DC.Identifier" content="migrating-ant-to-dita"><link rel="stylesheet" type="text/css" href="../css/commonltr.css"><link rel="stylesheet" type="text/css" href="../css/dita-ot-doc.css"><title>Migrating Ant builds to use the dita command</title></head><body id="migrating-ant-to-dita"><header role="banner"><div class="header">
  4. <p>DITA Open Toolkit</p>
  5. <hr>
  6. </div></header><nav role="toc"><ul><li><a href="../index.html">DITA Open Toolkit 3.0</a></li><li><a href="../release-notes/index.html">Release Notes</a></li><li><a href="../topics/installing-client.html">Installing DITA-OT</a></li><li><a href="../topics/alternative-input-formats.html">Authoring formats</a></li><li><a href="../topics/building-output.html">Building output</a><ul><li><a href="../topics/build-using-dita-command.html">Using the dita command</a><ul><li><a href="../topics/using-dita-properties-file.html">Using a properties file</a></li><li class="active"><a href="../topics/migrating-ant-to-dita.html">Migrating Ant builds</a></li></ul></li><li><a href="../topics/publishing-with-ant.html">Using Ant</a></li><li><a href="../topics/output-formats.html">Output formats</a></li></ul></li><li><a href="../parameters/index.html">Setting parameters</a></li><li><a href="../topics/extending-the-ot.html">Customizing DITA-OT</a></li><li><a href="../topics/troubleshooting-overview.html">Troubleshooting</a></li><li><a href="../reference/index.html">Reference</a></li><li><a href="../topics/dita-and-dita-ot-resources.html">Resources</a></li></ul></nav><main role="main"><article role="article" aria-labelledby="ariaid-title1">
  7. <h1 class="title topictitle1" id="ariaid-title1">Migrating Ant builds to use the <span class="keyword cmdname">dita</span> command</h1>
  8. <div class="body taskbody"><p class="shortdesc">Although Ant builds are still supported in the DITA Open Toolkit, you might want to switch to use the new
  9. <span class="keyword cmdname">dita</span> command.</p>
  10. <section class="section context"><div class="tasklabel"><h2 class="sectiontitle tasklabel">About this task</h2></div>
  11. <p class="p">Building output with the <span class="keyword cmdname">dita</span> command is often easier than using Ant. In particular, you can
  12. use <span class="ph filepath">.properties</span> files to specify sets of DITA-OT parameters for each build.</p>
  13. <p class="p">You can include the <span class="keyword cmdname">dita</span> command in shell scripts to perform multiple builds.</p>
  14. <div class="note tip note_tip"><span class="note__title">Tip:</span> Add the absolute path for <span class="ph filepath"><var class="keyword varname">dita-ot-dir</var></span><span class="ph filepath">/bin</span> to the <var class="keyword varname">PATH</var> environment variable to run the
  15. <span class="keyword cmdname">dita</span> command from any location on the file system without typing the path.</div>
  16. </section>
  17. <div class="tasklabel"><h2 class="sectiontitle tasklabel">Procedure</h2></div><ol class="ol steps"><li class="li step stepexpand">
  18. <span class="ph cmd">In your Ant build file, identify the properties set in each build target.</span>
  19. <div class="itemgroup info">
  20. <div class="note note note_note"><span class="note__title">Note:</span> Some build parameters might be specified as properties of the project as a whole. You can refer to a
  21. build log to see a list of all properties that were set for the build.</div>
  22. </div>
  23. </li><li class="li step stepexpand">
  24. <span class="ph cmd">Create a <span class="ph filepath">.properties</span> file for each build and specify the needed build parameters, one
  25. per line, in the format <code class="ph codeph">name = value</code>.</span>
  26. </li><li class="li step stepexpand">
  27. <span class="ph cmd">Use the <span class="keyword cmdname">dita</span> command to perform each build, referencing your
  28. <span class="ph filepath">.properties</span> with the <span class="keyword parmname">--propertyfile</span>=<var class="keyword varname">file</var>
  29. option.</span>
  30. </li></ol>
  31. <div class="example"><h2 class="title sectiontitle">Example: Ant build</h2>
  32. <div class="p">Sample build file: <span class="ph filepath" id="migrating-ant-to-dita__samples-dir"><var class="keyword varname">dita-ot-dir</var>/docsrc/samples</span><span class="ph filepath">/ant_sample/build-chm-pdf.xml</span>
  33. <pre class="pre codeblock"><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  34. &lt;project name="build-chm-pdf" default="all" basedir="."&gt;
  35. &lt;property name="dita.dir" location="${basedir}/../../.."/&gt;
  36. &lt;target name="all" description="build CHM and PDF" depends="chm,pdf"/&gt;
  37. &lt;target name="chm" description="build CHM"&gt;
  38. &lt;ant antfile="${dita.dir}/build.xml"&gt;
  39. &lt;property name="args.input" location="../sequence.ditamap"/&gt;
  40. &lt;property name="transtype" value="htmlhelp"/&gt;
  41. &lt;property name="output.dir" location="../out/chm"/&gt;
  42. &lt;property name="args.gen.task.lbl" value="YES"/&gt;
  43. &lt;/ant&gt;
  44. &lt;/target&gt;
  45. &lt;target name="pdf" description="build PDF"&gt;
  46. &lt;ant antfile="${dita.dir}/build.xml"&gt;
  47. &lt;property name="args.input" location="../taskbook.ditamap"/&gt;
  48. &lt;property name="transtype" value="pdf"/&gt;
  49. &lt;property name="output.dir" location="../out/pdf"/&gt;
  50. &lt;property name="args.gen.task.lbl" value="YES"/&gt;
  51. &lt;property name="args.rellinks" value="nofamily"/&gt;
  52. &lt;/ant&gt;
  53. &lt;/target&gt;
  54. &lt;/project&gt;</code></pre></div></div>
  55. <div class="example"><h2 class="title sectiontitle">Example: <span class="ph filepath">.properties</span> files with <span class="keyword cmdname">dita</span> command</h2>
  56. <p class="p">The following <span class="ph filepath">.properties</span> files and <span class="keyword cmdname">dita</span> commands are equivalent to the
  57. example Ant build.</p>
  58. <div class="p">Sample <span class="ph filepath">.properties</span> file: <span class="ph filepath"><var class="keyword varname">dita-ot-dir</var>/docsrc/samples</span><span class="ph filepath">/properties/chm.properties</span><pre class="pre codeblock"><code>output.dir = out/chm
  59. args.gen.task.lbl = YES
  60. args.breadcrumbs = yes</code></pre></div>
  61. <div class="p">Sample <span class="ph filepath">.properties</span> file: <span class="ph filepath"><var class="keyword varname">dita-ot-dir</var>/docsrc/samples</span><span class="ph filepath">/properties/pdf.properties</span><pre class="pre codeblock"><code>output.dir = out/pdf
  62. args.gen.task.lbl = YES
  63. args.rellinks = nofamily</code></pre></div>
  64. <p class="p">Run from <span class="ph filepath"><var class="keyword varname">dita-ot-dir</var>/docsrc/samples</span>:</p>
  65. <pre class="pre codeblock"><code><span class="keyword cmdname">dita</span> <span class="keyword parmname">--input</span>=<span class="ph filepath">sequence.ditamap</span> <span class="keyword parmname">--format</span>=<span class="keyword option">htmlhelp</span> \
  66. <span class="keyword parmname">--propertyfile</span>=<span class="ph filepath">properties/chm.properties</span>
  67. <span class="keyword cmdname">dita</span> <span class="keyword parmname">--input</span>=<span class="ph filepath">taskbook.ditamap</span> <span class="keyword parmname">--format</span>=<span class="keyword option">pdf</span> \
  68. <span class="keyword parmname">--propertyfile</span>=<span class="ph filepath">properties/pdf.properties</span></code></pre>
  69. </div>
  70. <div class="example"><h2 class="title sectiontitle">Example: Call the <span class="keyword cmdname">dita</span> command from an Ant build</h2>
  71. <p class="p">In some cases, you might still want to use an Ant build to implement some pre- or post-processing steps, but
  72. also want the convenience of using the <span class="keyword cmdname">dita</span> command with <span class="ph filepath">.properties</span>
  73. files to define the parameters for each build. This can be accomplished with Ant's <code class="keyword markupname xmlelement">&lt;exec&gt;</code>
  74. task.</p>
  75. <p class="p">This example uses a <code class="keyword markupname xmlelement">&lt;dita-cmd&gt;</code> Ant macro defined in the <span class="ph filepath"><var class="keyword varname">dita-ot-dir</var>/docsrc/samples</span><span class="ph filepath">/ant_sample/dita-cmd.xml</span> file:</p>
  76. <pre class="pre codeblock"><code> &lt;macrodef name="dita-cmd"&gt;
  77. &lt;attribute name="input"/&gt;
  78. &lt;attribute name="format"/&gt;
  79. &lt;attribute name="propertyfile"/&gt;
  80. &lt;sequential&gt;
  81. &lt;exec executable="${dita.dir}/bin/dita"&gt;
  82. &lt;arg line="--input=@{input} --format=@{format} --propertyfile=@{propertyfile}"/&gt;
  83. &lt;/exec&gt;
  84. &lt;/sequential&gt;
  85. &lt;/macrodef&gt;</code></pre>
  86. <div class="p">You can use this macro in your Ant build to call the <span class="keyword cmdname">dita</span> command and pass the
  87. <span class="keyword parmname">input</span>, <span class="keyword parmname">format</span> and <span class="keyword parmname">propertyfile</span> parameters as
  88. follows:
  89. <pre class="pre codeblock"><code>&lt;dita-cmd input="sample.ditamap" format="pdf" propertyfile="sample.properties"/&gt;</code></pre>
  90. </div>
  91. <p class="p">This approach allows you to use Ant builds to perform additional tasks at build time while allowing the
  92. <span class="keyword cmdname">dita</span> command to set the classpath and ensure that all necessary JAR libraries are
  93. available.</p>
  94. <div class="note note note_note"><span class="note__title">Note:</span> The attributes defined in the Ant macro are required and must be supplied each time the task is run. To set
  95. optional parameters in one build (but not another), use different <span class="ph filepath">.properties</span> files for
  96. each build.</div>
  97. <div class="p">Sample build file: <span class="ph filepath"><var class="keyword varname">dita-ot-dir</var>/docsrc/samples</span><span class="ph filepath">/ant_sample/build-chm-pdf-hybrid.xml</span>
  98. <pre class="pre codeblock"><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  99. &lt;project name="build-chm-pdf-hybrid" default="all" basedir="."&gt;
  100. &lt;description&gt;An Ant build that calls the dita command&lt;/description&gt;
  101. &lt;include file="dita-cmd.xml"/&gt;&lt;!-- defines the &lt;dita-cmd&gt; macro --&gt;
  102. &lt;target name="all" depends="pre,main,post"/&gt;
  103. &lt;target name="pre"&gt;
  104. &lt;description&gt;Preprocessing steps&lt;/description&gt;
  105. &lt;/target&gt;
  106. &lt;target name="main"&gt;
  107. &lt;description&gt;Build the CHM and PDF with the dita command&lt;/description&gt;
  108. &lt;dita-cmd input="../sequence.ditamap" format="htmlhelp" propertyfile="../properties/chm.properties"/&gt;
  109. &lt;dita-cmd input="../taskbook.ditamap" format="pdf" propertyfile="../properties/pdf.properties"/&gt;
  110. &lt;/target&gt;
  111. &lt;target name="post"&gt;
  112. &lt;description&gt;Postprocessing steps&lt;/description&gt;
  113. &lt;/target&gt;
  114. &lt;/project&gt;</code></pre>
  115. </div>
  116. </div>
  117. </div>
  118. <nav role="navigation" class="related-links"><div class="familylinks"><div class="parentlink"><strong>Parent topic:</strong> <a class="link" href="../topics/build-using-dita-command.html" title="You can generate output using the DITA Open Toolkit dita command-line tool. Build parameters can be specified on the command line or with .properties files.">Building output using the dita command</a></div></div></nav></article></main></body></html>