Some Useful Ant Tasks

, No Comments »

Copying a File to a Server Running SSH Daemon

  1. Download the jsch jar file from (http://www.jcraft.com/jsch/)
    > wget http://prdownloads.sourceforge.net/jsch/jsch-x.x.x.jar
  2. Copy the jar file into the lib directory of your ANT HOME
    > cp jsch-x.x.x.jar ${ANT_HOME}/lib
  3. Use the scp ant task in the build script
    <scp file="file.txt" todir="user:password@hostname:/remotedir"/>

Selecting Files by Size

The <size> tag in a FileSet will determine if the files should be included or not depending on the size limit specified.

<fileset dir="${jar.path}">
    <patternset>
        <include name="**/*.jar"/>
    </patternset>
    <size value="0" units="k" when="more"/>
</fileset>

value - is the size of the value to be tested
units - unit to be tested against: k, M, G
when - type of comparison to be used: less, equal, more

Execute Target Based on Conditional Logic

Ant doesn’t support true conditional logic, such as if/then/else. However, you can execute targets depending on the state of properties. For example the target executes if the dummy property is set:

<target name="run" if="dummy"/>

If the property is not set, the target is ignored. You can also specify that a target should execute unless a property is set:

<target name="run" unless="dummy"/>

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in