3.2.3. Using the Ant Tasks

To use the BundleWorks Ant tasks, you need to first load BundleWorks, then reference the BundleWorks tasks using the 'taskdef' command inside your build.xml.

The following is an example ant build.xml file which simply prints help for the 'add' command.

<?xml version="1.0"?>
<project name="bundleworks" default="help" basedir=".">
   <taskdef resource="org/bundleworks/ant/antlib.xml" />
   <target name="help">
      <bw.help topic="add"/>
   </target>
</project>

To find the names of the Ant task parameters refer to the Reference section of this manual. Each command has an Ant Usage section showing the task parameters. As an example, the add command takes the ant task parameters "archive" and "path" as shown below:

<?xml version="1.0"?>
<project name="bundleworks" default="add" basedir=".">
   <taskdef resource="org/bundleworks/ant/antlib.xml" />
   <target name="add">
      <bw.add archive="/tmp/helloserver-2.0.tgz" path="/opt/bundles"/>
   </target>
</project>

You can change standard in, standard out, and standard error for any Ant task by using the task parameters input, output, and error, respectively. This is useful for saving task output to a file or for providing an input file to answer questions during deployment, as in the following example.

<target name="dist" depends="bundle">
   <bw.add archive="${dist.dir}/${bundle.name}-${bundle.version}.tgz" 
      path="/opt/bundles" />
   <bw.deploy bundle="/opt/bundles/${bundle.name}/${bundle.version}" 
      environment="/var/env/dev" input="upgrade.in" />
</target>

Note that none of the ant tasks provide confirmation prompts like some of the command line actions (deploy, remove, etc.). You need to be careful with their usage.