Sunday, July 5, 2009

Ant, SCP and EC2

I've have had to deal with a strange set of circumstances

1. No ant-jsh.jar in my deployment

I got the error

BUILD FAILED

Deploy.ant.xml:57: Problem: failed to create task or type scp

Cause: the class org.apache.tools.ant.taskdefs.optional.ssh.Scp was not found.

This looks like one of Ant's optional components.

Action: Check that the appropriate optional JAR exists in

-/usr/share/ant/lib

-/Users/alvinrichards/.ant/lib

-a directory added on the command line with the -lib argument


Do not panic, this is a common problem.

The commonest cause is a missing JAR.


This is not a bug; it is a configuration problem

Turns out that the default deployment of Ant (1.7) did not contain this jar on Mac OS-x 10.5. So I had to do two things

  1. Download the binary distribution of Ant 1.7, unpack the jar and copy ant-jsch.jar to /usr/share/ant/lib
  2. Download the implementation of the SSH java code from JCraft and copy it to /usr/share/ant/lib


2. I still can't SCP to EC2

So I know I can scp -i to this EC2 host, but the following Ant task fails

<scp localfile="dba.war"

todir="root@xxxx:/usr/java/apache-tomcat-6.0.14/webapps/"

keyfile="xxxx-Amazon-LAMP-image-keypair">

with

BUILD FAILED

/Volumes/Develop/Develop/Projects/HarpoonDeployMK9a/Deploy.ant.xml:57: neither password nor passphrase for user root has been given. Can't authenticate.

Turns out that you need the following in the SCP task for it to work with EC2

trust="yes"

passphrase="xxx"

The passphrase that worked happened to be my password for my AWS account...

2 comments:

trk9 said...

ahhhhaaaaaaaaaaa!!!!

man thank you! i was pulling my hair out over this too. very irritating that mac osx ships without ant-jsch.jar. i grabbed it from the binary as you did and my scp instantly worked (after placing jsch.jar in ANT_HOME/lib of course).

post much appreciated!

colin

chubbard said...

Adding passphrase="" to your scp task works as well so you don't have to hard code your account password in there. Probably should fix that in ant scp. :-)