Friday, 15 June 2007

Eclipse, Ant and SSH

Getting Ant to work with a secure (SSH) connection requires a few more steps in the process.

Here's some guidelines which may help anyone wanting to run ant builds using SSH:

1. Once you've installed Eclipse, Ant and all the other bits, go and grab this:

2. Copy the jar files in the archive over to wherever you installed Ant (in Windows, could be something like C:/Apps/apache-ant-1.6.5/lib/; on Linux it could be something like /home/{YOUR_USER_NAME}/apps/apache-ant-1.6.5/lib/)

3. Add maverick-ant.jar to your classpath in Eclipse (Window > Preferences > Ant > Editor > Runtime > Add External Jars) OR set the Ant Home (using the Ant Home button) and point to the base folder {YOUR_LOCATION}/apps/apache-ant-1.6.5

4. Go and get puttygen from

5. Select 'Generate' and move the mouse around; this will create a random key pair.

6. Create (and confirm) a key passphrase to add another layer of security

7. Copy the Public key information Putty Key Generator has returned

8. Log into your server (wherever you're SSHing to) using the normal method (we're using Putty here)

9. edit /home/YOUR_USER_ID/.ssh/authorized_keys using your favourite editor and append the key information to that file, write the file and quit.

(I put an empty line in between the entries and this worked fine)

10. Save the private key locally using the save private key button in puttygen (you'll need to be able to refer to this in your ANT xml below)

11. Test it out in eclipse - create a build.xml file in your project, use the information below as a template and run the xml as an Ant build.

i. A basic ANT script for authentication should look like this - I've added the ls command in to show it working, so the ant file will authenticate (and show you the stages of authentication) and will then execute 'ls' to retrieve a directory listing:

<?xml version="1.0" encoding="UTF-8"?>

<project name="ssh" default="files" basedir=".">

<taskdef name="ssh"
classpath="{THE_PATH_TO_YOUR_ANT_FOLDER}/lib/maverick-ant.jar" />

<target name="files">
<exec cmd="ls" />


Hope this helps. More information (as a tutorial) regarding ANT can be found here:

And check the documentation that came with Maverick Ant for more information:

No comments: