Adding optional tasks to Apache Ant
Introduction
Ant build tool provides many tasks out of the box but some have to be added separately. This document explains how to do it.
For information on how to install Ant build tool visit this link: Installing Ant on Linux
Why optional tasks ?
Optional tasks are provided by third party software, and many require additional libraries. For most jobs Ant works fine without optional tasks. However there are some extra tasks that are very useful (like scp).
Install Ant optional tasks
I'm going to assume you installed Ant in /opt/ant/apache-ant-<version> folder and created a default symbolic link pointing to it. Open a terminal and go to that folder. You need to login as root. If you're using Gnome Linux desktop open Root Terminal window (Applications/Accessories/Root Terminal). Otherwise just open a terminal and login as root (su). Press ENTER after each command.
cd /opt/ant/default
ant -f fetch.xml -Ddest=system
You should see a message saying:
Downloading to /opt/ant/apache-ant-<version>/lib
Followed by many log messages.
Last message should say something like:
BUILD SUCCESSFUL
Total time: 1 minute 45 seconds
You should now have access to optional Ant tasks.
Using scp optional task
If you want to deploy files to remote host accessible by ssh you can use scp task to do that. Add one of the commands below to your Ant script (build.xml):
If you know the user name and password for remote host:
<scp todir="userName@remoteHost:remoteDir" file="fileName" passphrase="secret" />
If your account has a public key registered with remote host and your ssh user name is the same as your login name:
<scp todir="${user.name}@remoteHost:remoteDir" file="${fileName}" keyfile="${user.home}/.ssh/id_rsa" />
Property ${fileName}
is an Ant property storing file name of the file you want to copy.
What if scp task does not work ?
You can always call scp program directly. Add these commands to your Ant script:
<exec executable="scp">
<arg value="${fileName}" />
<arg value="${user.name}@remoteHost:remoteDir" />
</exec>
Again script above assumes your account has a public key registered with remote host.