Wednesday, August 29, 2012

Some ANT task

1. How to build  project from another build.

<target name="project2"
            description="Builds project2 project, required depedency">
        <!-- Build project2 first  -->

        <subant target="dist" verbose="yes" inheritall="false">
            <filelist dir="../com.waheed.project2"
                      files="build.xml" />


2. How to read SVN revision and write into some file

<loadfile property="revision" srcFile="./.svn/entries">
            <headfilter skip="3" lines="1"/>
                <format property="date" pattern="dd/MM/yyyy hh:mm:ss" />
            <echo append="true" file="<FILE_NAME>" >revision=${revision}${line.separator}</echo>

3. How to generate Keystore

    <target name="keystore">
        <delete file="workdir/keystore" failonerror="false"/>
        <genkey keystore="./keystore"
                <param name="CN" value="NAME" />
                <param name="OU" value="NAME_OF_ORGANIZATION_UNIT" />
                <param name="O" value="ORGANIZATION_NAME" />
                <param name="C" value="COUNTRY_NAME" />

4. How to get current time

<target name="time">
            <format property="build-time" pattern="yyyy-MM-dd-HH-mm" />

5 . How to create jar with manifest

 <jar jarfile="${dist}/name_of_jar.jar"
                <!-- Who is building this jar? -->
                <attribute name="Built-By" value="${}" />
                <!-- Information about the program itself -->
                <attribute name="Implementation-Vendor"
                           value="Implementation-Vendor" />
                <attribute name="Implementation-Title"
                           value="Implementation-Title" />
                <attribute name="Implementation-Version" value="1.0" />
                <!-- details -->
                <section name="PATH_TO_MAIN_CLASS">
                    <attribute name="Sealed" value="false" />

6. How to compile source

 <!-- Compile the java code from ${src} into ${build} -->

        <javac destdir="bin" debug="true">
            <src path="src" />
                <pathelement location="../dependency/bin" />
                <fileset dir="../lib">
                    <include name="*.jar" />

7. How to compile source with dependency class path

 <path id="class.path">
        <fileset dir="../lib/folder1">
            <include name="*.jar" />
        <fileset dir="../lib/folder2">
             <include name="*.jar" />

 <!-- Compile the java code from ${src} into ${build} -->
        <javac destdir="bin" debug="true">
            <src path="src" />
            <classpath refid="class.path" />

8.  How to build Zip file

    <property name="" value="product1" />
    <property name="product.version" value="1.0" />

<zip basedir="${dist}" destfile="${dist}/${}-${product.version}.zip">

9. How to build tar file

    <property name="" value="product1" />
    <property name="product.version" value="1.0" />

<exec executable="tar" dir="${dist}">
            <arg value="czf" />
            <arg value="${dist}/${}-${product.version}.tgz" />
            <arg value="." />

10 . How to check OS 

<condition property="isWindows">
        <os family="windows" />

    <condition property="isUnix">
        <os family="unix" />

    <target name="" if="isWindows" depends="a">
<!--  Task to be done-- >

    <target name="dist.unix" if="isUnix" depends="b">

<!--  Task to be done-- >

11.  How to set permission to file

 <chmod perm="500">
            <fileset dir="${dist}">
                <include name="**/*.sh" />
                <include name="jsvc" />

12 .How to read property file

Suppose I have following data in my file and want to read it and write it to another file lets say name

     <property file="${dist}/" prefix="version"/>
       <echo file="${dist}/" append="true">revision ${version.REVISION}${line.separator}</echo>