Thomas Sundberg

January 16, 2012

ssh from Ant

Filed under: Automation — Tags: , , , — Thomas Sundberg @ 02:02

This post has been migrated to

You have to patch Ant in order to run ssh from it. It needs a ssh implementation that isn’t bundled with the default distribution. If you just define a task like this:

<sshexec host="somehost"
    command="touch somefile"/>

Then you will get the error message below back.

/Users/tsu/projects/linkon/fp/sabine/resources/deploy/build.xml:57: Problem: failed to create task or type sshexec
Cause: the class was not found.
        This looks like one of Ant's optional components.
Action: Check that the appropriate optional JAR exists in
        -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

The solution is to download an ssh implementation and add it to your Ant installation. A valid implementation can be downloaded from JCraft. When you have downloaded and verified jsch-0.1.45.jar all you have to do is add it to your Ant installation. My installation was located at /usr/share/ant/ so I added it to /usr/share/ant/lib

I you are on a Mac, which I am, then this may not be sufficient. If you still get the error above, then take a look at a blog post I just wrote about ant being broken on Mac.



  1. That’s too much hassle to get up and running. I quit using sshexec because of all these problems.

    It is much easier to use Ant exec with ssh. The equivalent of the above is:

    Comment by Rob Juurlink — January 16, 2012 @ 22:15

  2. <exec executable=”ssh” os=”Linux, ‘Mac OS X'”>
    <arg line=”-n -i ${keyfile} ${username}@${host} touch somefile”/>

    Comment by Rob Juurlink — January 16, 2012 @ 22:16

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at

%d bloggers like this: