plugin-javalib.dita 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE task PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
  3. <!-- This file is part of the DITA Open Toolkit project. See the accompanying LICENSE file for applicable license. -->
  4. <task id="plugin-javalib" xml:lang="en-US">
  5. <title>Adding a Java library to the DITA-OT <parmname>classpath</parmname></title>
  6. <titlealts>
  7. <navtitle>Adding a Java library to the <parmname>classpath</parmname></navtitle>
  8. </titlealts>
  9. <shortdesc>You can use the <codeph>dita.conductor.lib.import</codeph> extension point to add an additional Java
  10. library to the DITA-OT <parmname>classpath</parmname> parameter.</shortdesc>
  11. <prolog>
  12. <metadata>
  13. <keywords>
  14. <indexterm>deprecated features<indexterm><codeph>dost.class.path</codeph> property</indexterm></indexterm>
  15. <indexterm>plug-ins<indexterm>Java</indexterm></indexterm>
  16. <indexterm>Java<indexterm>classpath</indexterm></indexterm>
  17. <indexterm>classpath<indexterm>Java</indexterm></indexterm>
  18. <indexterm>XSLT<indexterm>Java</indexterm></indexterm>
  19. </keywords>
  20. </metadata>
  21. </prolog>
  22. <taskbody>
  23. <context>
  24. <p>As of DITA-OT 3.1, the Java class path is managed automatically, meaning you do not (and should not) use
  25. explicit references to Java class paths in your build scripts. In particular, the old
  26. <codeph>dost.class.path</codeph> property has been deprecated and should not be used. If you are migrating
  27. older plug-ins that manage their class path directly, you should remove any explicit class path configuration.
  28. If your plug-in was not already using the <codeph>dita.conductor.lib.import</codeph> extension point to
  29. integrate its JAR dependencies you must add it.</p>
  30. <p>The effective DITA-OT class path is the combination of the JAR files in the main <filepath>lib/</filepath>
  31. directory and the plug-in-contributed JARs, which are listed in <filepath>config/env.sh</filepath>. The
  32. <filepath>env.sh</filepath> file is updated automatically when plug-ins are installed or removed.</p>
  33. </context>
  34. <steps>
  35. <step>
  36. <cmd>If necessary, compile the Java code into a JAR file.</cmd>
  37. </step>
  38. <step>
  39. <cmd>Create a <filepath>plugin.xml</filepath> file that contains the following code:</cmd>
  40. <info><codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace">&lt;plugin id="<varname>plugin-id</varname>">
  41. &lt;feature extension="dita.conductor.lib.import" file="<varname>file</varname>"/>
  42. &lt;/plugin></codeblock>where:
  43. <ul>
  44. <li><varname>plugin-id</varname> is the plug-in identifier, for example,
  45. <codeph>com.example.addjar</codeph>.</li>
  46. <li><varname>file</varname> is the name of the JAR file, for example,
  47. <filepath>myJavaLibrary.jar</filepath>. </li>
  48. </ul></info>
  49. </step>
  50. <step>
  51. <cmd>Install the plug-in.</cmd>
  52. </step>
  53. </steps>
  54. <result>The Ant or XSLT code now can make use of the Java code.</result>
  55. <example>
  56. <p>In the following extended example, the <filepath>myJavaLibrary.jar</filepath> file performs a validation step
  57. during processing, and you want it to run immediately before the <codeph>conref </codeph>step.</p>
  58. <p>To accomplish this, you will need to use several features:</p>
  59. <ul>
  60. <li>The JAR file must be added to the classpath.</li>
  61. <li>The Ant target must be added to the dependency chain for conref.</li>
  62. <li>An Ant target must be created that uses this class, and integrated into the code.</li>
  63. </ul>
  64. <p>The files might look like the following:</p>
  65. <fig>
  66. <title><filepath>plugin.xml</filepath> file</title>
  67. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace">&lt;?xml version="1.0" encoding="UTF-8"?>
  68. &lt;plugin id="com.example.samplejava">
  69. <i>&lt;!-- Add the JAR file to the DITA-OT CLASSPATH --></i>
  70. <b>&lt;feature extension="dita.conductor.lib.import"
  71. file="com.example.sampleValidation.jar"/></b>
  72. <i>&lt;!-- Integrate the Ant code --></i>
  73. &lt;feature extension="ant.import" file="calljava-antcode.xml"/>
  74. <i>&lt;!-- Define the Ant target to call, and when (before conref) --></i>
  75. &lt;feature extension="depend.preprocess.conref.pre"
  76. value="validateWithJava"/>
  77. &lt;/plugin></codeblock>
  78. </fig>
  79. <fig>
  80. <title><filepath>calljava-antcode.xml</filepath> file</title>
  81. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace">&lt;?xml version="1.0" encoding="UTF-8"?>
  82. &lt;project default="validateWithJava">
  83. &lt;target name="validateWithJava">
  84. &lt;java classname="com.example.sampleValidation">
  85. &lt;!-- The class was added to the DITA-OT classpath -->
  86. &lt;/java>
  87. &lt;/target>
  88. &lt;/project></codeblock>
  89. </fig>
  90. </example>
  91. </taskbody>
  92. </task>