migrating-ant-to-dita.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 2016"><meta name="DC.rights.owner" content="(C) Copyright 2016"><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.Format" content="XHTML"><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></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 tiptitle">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 notetitle">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> file with the <span class="keyword parmname">-propertyfile</span> option.</span>
  29. </li></ol>
  30. <div class="example"><h2 class="title sectiontitle">Example: Ant build</h2>
  31. <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>
  32. <pre class="pre codeblock"><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  33. &lt;project name="build-chm-pdf" default="all" basedir="."&gt;
  34. &lt;property name="dita.dir" location="${basedir}/../../.."/&gt;
  35. &lt;target name="all" description="build CHM and PDF" depends="chm,pdf"/&gt;
  36. &lt;target name="chm" description="build CHM"&gt;
  37. &lt;ant antfile="${dita.dir}/build.xml"&gt;
  38. &lt;property name="args.input" location="../sequence.ditamap"/&gt;
  39. &lt;property name="transtype" value="htmlhelp"/&gt;
  40. &lt;property name="output.dir" location="../out/chm"/&gt;
  41. &lt;property name="args.gen.task.lbl" value="YES"/&gt;
  42. &lt;property name="args.breadcrumbs" 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="ph filepath"><var class="keyword varname">dita-ot-dir</var>/bin/<span class="keyword cmdname">dita</span></span> -input sequence.ditamap -format htmlhelp -propertyfile properties/chm.properties
  66. <span class="ph filepath"><var class="keyword varname">dita-ot-dir</var>/bin/<span class="keyword cmdname">dita</span></span> -input taskbook.ditamap -format pdf -propertyfile properties/pdf.properties</code></pre>
  67. </div>
  68. <div class="example"><h2 class="title sectiontitle">Example: Call the <span class="keyword cmdname">dita</span> command from an Ant build</h2>
  69. <p class="p">In some cases, you might still want to use an Ant build to implement some pre- or post-processing steps, but
  70. also want the convenience of using the <span class="keyword cmdname">dita</span> command with <span class="ph filepath">.properties</span>
  71. files to define the parameters for each build. This can be accomplished with Ant's <code class="keyword markupname xmlelement">&lt;exec&gt;</code>
  72. task.</p>
  73. <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>
  74. <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>
  75. <pre class="pre codeblock"><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  76. &lt;project name="build-chm-pdf-hybrid" default="all" basedir="."&gt;
  77. &lt;description&gt;An Ant build that calls the dita command&lt;/description&gt;
  78. &lt;include file="dita-cmd.xml"/&gt;&lt;!-- defines the &lt;dita-cmd&gt; macro --&gt;
  79. &lt;target name="all" depends="pre,main,post"/&gt;
  80. &lt;target name="pre"&gt;
  81. &lt;description&gt;Preprocessing steps&lt;/description&gt;
  82. &lt;/target&gt;
  83. &lt;target name="main"&gt;
  84. &lt;description&gt;Build the CHM and PDF with the dita command&lt;/description&gt;
  85. &lt;dita-cmd input="../sequence.ditamap" format="htmlhelp" propertyfile="../properties/chm.properties"/&gt;
  86. &lt;dita-cmd input="../taskbook.ditamap" format="pdf" propertyfile="../properties/pdf.properties"/&gt;
  87. &lt;/target&gt;
  88. &lt;target name="post"&gt;
  89. &lt;description&gt;Postprocessing steps&lt;/description&gt;
  90. &lt;/target&gt;
  91. &lt;/project&gt;</code></pre>
  92. </div>
  93. </div>
  94. </div>
  95. </article></main></body></html>