Friday, June 1, 2012

Executing SSH commands from ANT

ou can easily achieve remote command invocation, using an ANT Task sshexec. An example of its usage could be this snippet (note that remote.* variables are taken from the *.properties file in this case):

<sshexec host="${remote.host}"
         username="${remote.user}"
         password="${remote.pass}"
         trust="true"
         command="rm -rf ${remote.webapps.path}/ROOT*" />


You can read about more detailed examples here.

To add this feature to your ANT installation, you need to download the JSch – Java Secure Channel library and include the jsch jar file into ANT classpath (i.e. in your ANT_HOME/lib/ or — if you’re using an Eclipse — into Eclipse Ant classpath).

I found this feature quite useful as it reduced time I needed to build and deploy an application.

No comments: