Using Ant scripts to publish UML models

You can use Apache Ant scripts to publish UML models. You can set the scripts to publish the models automatically when you make changes to the models.
About this task

Apache Ant is an open-source, Java-based build tool. You can create and run Ant build files from the workbench. The Ant build files can operate on resources in the file system as well as resources in the workspace.

These instructions are for using Ant build files to publish models from within the workbench. For more information about the Ant build tool, see the Apache Ant Web site and the workbench overview topics.

The Ant script element that handles model publishing is the custom element com.ibm.xtools.publish.CLModelPublish. A script can contain more than one of these elements if you need to publish multiple models.

To publish a model by using an Ant script:

  1. In the Project Explorer view, in a project, create a new file with an XML extension.
  2. Set the Ant editor as the default editor for this file:
    1. Click Window > Preferences.
    2. Expand General, expand Editors, and click File Associations.
    3. To the right of the File types list, click Add, type a name for the XML file, and click OK.
    4. From the File types list, select the XML file.
    5. From the Associated editors list, select Ant Editor, click Default, and click OK. If the Ant Editor is not in the list, click Add to add it.
    6. If the XML file is open, close it; then double-click the file to open it in the default Ant editor.
  3. In the XML file, type <pr and, in the element completion window, double-click the <project> element.
  4. Assign a default target in the <project> element; for example, <project default="MyTarget">.
  5. Between the opening and closing <project> element tags, create a target; for example, <project default="MyTarget"><target name="MyTarget"></target></project>.
  6. Between the opening and closing <target> element tags, type <pu and select PublishModel from the completion list. This adds the com.ibm.xtools.publish.CLModelPublish element to your Ant script.
  7. Specify values for the task parameters, and click File > Save.
    Note: For syntax information, see the topic "Ant syntax for UML model publishing."
    The script should look similar to this example:
    <project default="MyTarget"><target name="MyTarget">
             <com.ibm.xtools.publish.CLModelPublish 
             modelPath="C:\workspace\MyProject\MyModel.emx" 
             outputFolder="c:\temp\pubweb" 
             outputFilename="index.html" 
             overwriteExisting="true" 
             preview="false" 
             showIcons="true"
             genDate="false"
             diagramImageFormat="gif"
             detailLevel="full"
             errorHandling="ignore"/> 
    
    </target></project>
  8. In the Project Explorer view, right-click the XML file and then click Run As > Ant Build .... Be sure to click Ant Build ..., and not Ant Build.
  9. On the JRE page of the dialog box, under Runtime JRE, click Run in the same JRE as workspace.
  10. To run the script and publish the model, click Apply and click Run.
What to do next

You can also set the Ant script as a build file that runs automatically whenever a model is modified. For more information, work through the tutorial named "Automate publishing and reporting with Apache Ant."


Feedback