plugin-javalib.html 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <!DOCTYPE html
  2. SYSTEM "about:legacy-compat">
  3. <html lang="en-us"><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="You can use the dita.conductor.lib.import extension point to add an additional Java library to the DITA-OT classpath parameter."><meta name="DC.Relation" scheme="URI" content="../dev_ref/plugin-creating.html"><meta name="DC.Relation" scheme="URI" content="../dev_ref/plugin-extension-points-general.html"><meta name="DC.Relation" scheme="URI" content="../dev_ref/plugins-installing.html"><meta name="DC.Format" content="XHTML"><meta name="DC.Identifier" content="plugin-javalib"><meta name="DC.Language" content="en-US"><link rel="stylesheet" type="text/css" href="../css/commonltr.css"><link rel="stylesheet" type="text/css" href="../css/dita-ot-doc.css"><title>Adding a Java library to the DITA-OT classpath parameter</title></head><body id="plugin-javalib"><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 2.3</a></li><li><a href="../release-notes/index.html">Release Notes</a></li><li><a href="../getting-started/index.html">Getting Started</a></li><li><a href="../user-guide/index.html">User Guide</a></li><li><a href="../parameters/index.html">Parameter Reference</a></li><li><a href="../dev_ref/index.html">Developer Reference</a><ul><li><a href="../dev_ref/DITA-OTArchitecture.html">DITA-OT Architecture</a></li><li><a href="../dev_ref/extending-the-ot.html">Extending the DITA-OT</a></li><li><a href="../dev_ref/plugin-creating.html">Creating plug-ins</a><ul><li><a href="../dev_ref/plugins-overview.html">Overview of plug-ins</a></li><li><a href="../dev_ref/plugin-xmlcatalog.html">Extending an XML catalog file</a></li><li><a href="../dev_ref/plugin-anttarget.html">Adding a new target to the Ant build process</a></li><li><a href="../dev_ref/plugin-antpreprocess.html">Adding an Ant target to the pre-processing pipeline</a></li><li><a href="../dev_ref/plugin-newtranstype.html">Adding a new transformation type</a></li><li><a href="../dev_ref/plugin-overridestyle.html">Overriding an XSLT-processing step</a></li><li><a href="../dev_ref/using-plugin-URI-extension.html">Referencing files from other plug-ins</a></li><li><a href="../dev_ref/plugin-addgeneratedtext.html">Modifying or adding generated text</a></li><li><a href="../dev_ref/plugin-xsltparams.html">Adding parameters to existing XSLT steps</a></li><li class="active"><a href="../dev_ref/plugin-javalib.html">Adding a Java library to the DITA-OT classpath parameter</a></li><li><a href="../dev_ref/plugin-messages.html">Adding new diagnostic messages</a></li><li><a href="../dev_ref/plugin-newextensions.html">Creating a new plug-in extension point</a></li><li><a href="../dev_ref/plugin-sample.html">Example plugin.xml file</a></li></ul></li><li><a href="../dev_ref/plugin-extension-points.html">Extension points</a></li><li><a href="../dev_ref/pdf-customization.html">Customizing PDF output</a></li><li><a href="../dev_ref/migration.html">Migrating customizations</a></li></ul></li><li><a href="../user-guide/dita-and-dita-ot-resources.html">DITA Resources</a></li></ul></nav><main role="main"><article role="article" aria-labelledby="ariaid-title1">
  7. <h1 class="title topictitle1" id="ariaid-title1">Adding a Java library to the DITA-OT <span class="keyword parmname">classpath</span> parameter</h1>
  8. <div class="body taskbody"><p class="shortdesc">You can use the <code class="ph codeph">dita.conductor.lib.import</code> extension point to add an additional Java
  9. library to the DITA-OT <span class="keyword parmname">classpath</span> parameter.</p>
  10. <div class="tasklabel"><h2 class="sectiontitle tasklabel">Procedure</h2></div><ol class="ol steps"><li class="li step stepexpand">
  11. <span class="ph cmd">If necessary, compile the Java code into a JAR file.</span>
  12. </li><li class="li step stepexpand">
  13. <span class="ph cmd">Create a <span class="ph filepath">plugin.xml</span> file that contains the following code:</span>
  14. <div class="itemgroup info"><pre class="pre codeblock"><code>&lt;plugin id="<var class="keyword varname">plugin-id</var>"&gt;
  15. &lt;feature extension="dita.conductor.lib.import" file="<var class="keyword varname">file</var>"/&gt;
  16. &lt;/plugin&gt;</code></pre>where:<ul class="ul">
  17. <li class="li"><var class="keyword varname">plugin-id</var> is the plug-in identifier, for example, com.example.addjar.</li>
  18. <li class="li"><var class="keyword varname">file</var> is the name of the JAR file, for example,
  19. <span class="ph filepath">myJavaLibrary.jar</span>. </li>
  20. </ul></div>
  21. </li><li class="li step stepexpand">
  22. <span class="ph cmd">Install the plug-in.</span>
  23. </li></ol>
  24. <section class="section result"><div class="tasklabel"><h2 class="sectiontitle tasklabel">Results</h2></div>The Ant or XSLT code now can make use of the Java code.</section>
  25. <div class="example"><div class="tasklabel"><h2 class="sectiontitle tasklabel">Example</h2></div>
  26. <p class="p">In the following extended example, the <span class="ph filepath">myJavaLibrary.jar</span> file performs a validation step
  27. during processing, and you want it to run immediately before the <code class="ph codeph">conref </code>step. To accomplish
  28. this, you will need to use several features:</p>
  29. <ul class="ul">
  30. <li class="li">The JAR file must be added to the classpath.</li>
  31. <li class="li">The Ant target must be added to the dependency chain for conref.</li>
  32. <li class="li">An Ant target must be created that uses this class, and the Ant wrapper integrated into the code.</li>
  33. </ul>
  34. <p class="p">The files might look like the following:</p>
  35. <figure class="fig fignone"><figcaption><span class="fig--title-label">Figure 1. </span><span class="ph filepath">plugin.xml</span> file</figcaption>
  36. <pre class="pre codeblock"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  37. &lt;plugin id="com.example.samplejava"&gt;
  38. &lt;!-- Add the JAR file to the DITA-OT CLASSPATH --&gt;
  39. <strong class="ph b">&lt;feature extension="dita.conductor.lib.import" file="com.example.sampleValidation.jar"/&gt;</strong>
  40. &lt;!-- Integrate the Ant code --&gt;
  41. &lt;feature extension="dita.conductor.target.relative" file="antWrapper.xml"/&gt;
  42. &lt;!-- Define the Ant target that is called, and the location (before conref) --&gt;
  43. &lt;feature extension="depend.preprocess.conref.pre" value="validateWithJava"/&gt;
  44. &lt;/plugin&gt;</code></pre>
  45. </figure>
  46. <figure class="fig fignone"><figcaption><span class="fig--title-label">Figure 2. </span><span class="ph filepath">antWrapper.xml</span> file</figcaption>
  47. <pre class="pre codeblock"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  48. &lt;dummy&gt;
  49. &lt;import file="calljava-antcode.xml"/&gt;
  50. &lt;/dummy&gt;</code></pre>
  51. </figure>
  52. <figure class="fig fignone"><figcaption><span class="fig--title-label">Figure 3. </span><span class="ph filepath">calljava-antcode.xml</span> file</figcaption>
  53. <pre class="pre codeblock"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  54. &lt;project default="validateWithJava"&gt;
  55. &lt;target name="validateWithJava"&gt;
  56. &lt;java classname="com.example.sampleValidation"&gt;
  57. &lt;!-- The class was added to dost.class.path (the DITA-OT classpath) --&gt;
  58. &lt;classpath refid="dost.class.path"/&gt;
  59. &lt;/java&gt;
  60. &lt;/target&gt;
  61. &lt;/project&gt;</code></pre>
  62. </figure>
  63. </div>
  64. </div>
  65. <nav role="navigation" class="related-links"><div class="familylinks"><div class="parentlink"><strong>Parent topic:</strong> <a class="link" href="../dev_ref/plugin-creating.html" title="You can use DITA-OT plug-ins to extend the DITA Open Toolkit.">Creating plug-ins</a></div></div><div class="linklist linklist relinfo reltasks"><strong>Related tasks</strong><br><div><a class="link" href="../dev_ref/plugins-installing.html" title="Use the dita command to install a plug-in.">Installing plug-ins</a></div></div><div class="linklist linklist relinfo relref"><strong>Related reference</strong><br><div><a class="link" href="../dev_ref/plugin-extension-points-general.html" title="These extension points enable you to extend the DITA-OT. You can add Ant targets or imports; add a Java library to the classpath parameter; add a new transformation type; extend a catalog file; add new diagnostic messages, and more.">General extension points</a></div></div></nav></article></main></body></html>