Developing Web Applications With Ant by Richard Hightower - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

An example that uses filters.

The setupProduction and setupDevelopment targets are executed conditionally based on the production property, then they set the filter to the proper JDBC driver:

 

<target name="setupProduction" if="production">
<filter token="jdbc_url" value="jdbc::production"/>
</target>
<target name="setupDevelopment" unless="production">
<filter token="jdbc_url" value="jdbc::development"/>
</target>

 

In our example, the filter in the setupProduction target sets jdbc_url to jdbc::production, while the filter in the setupDevelopment target sets jdbc_url to jdbc::development.

Later, when the script uses a copy task with filtering on, it applies the filter to all files in the file set specified by the copy. The copy task with filtering on replaces all occurrences of the string @jdbc_url@ with jdbc::production if the production property is set but to jdbc::development if the production property is not set.