Using FreeMarker with Ant

There are two ``FreeMarker Ant tasks'' that we know about:

This section introduces the FreemarkerXmlTask. For more information about FMPP visit its homepage:

In order to use the FreemarkerXmlTask, you must first define the freemarker.ext.ant.FreemarkerXmlTask inside your Ant buildfile, then call the task. Suppose you want to transform several XML documents to HTML using the hypothetical "xml2html.ftl" template, with XML documents being located in the directory "xml" and HTML documents generated into directory "html". You would write something like:

<taskdef name="freemarker" classname="freemarker.ext.ant.FreemarkerXmlTask">
    <pathelement location="freemarker.jar" />
<mkdir dir="html" />
<freemarker basedir="xml" destdir="html" includes="**/*.xml" template="xml2html.ftl" />  

The task would invoke the template for every XML document. Every document would be parsed into a DOM tree, then wrapped as a FreeMarker node variable. When template processing begins, the special variable, .node, is set to the root node of the XML document.

Note that if you are using the legacy (FreeMarker 2.2.x and earlier) XML adapter implementation, that still works, and the root of the XML tree is placed in the data-model as the variable document. That contains an instance of the legacy freemarker.ext.xml.NodeListModel class.

Note that all properties defined by the build file would be made available as a hash model named "properties". Several other models are made available; for detailed description of what variables are made available to templates as well as what other attributes can the task accept, see the JavaDoc for freemarker.ext.ant.FreemarkerXmlTask.

FreeMarker Manual -- For FreeMarker 2.3.20
HTML generated: 2013-06-27 20:54:33 GMT
Edited with XMLMind XML Editor