| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Ant example source code file (build.xml)

This example Ant source code file (build.xml) is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Ant tags/keywords

ant_home, ant_home, ant_home/bin/ant, ant_home_5_4, ant_home_6_4, ant_home_6_5, bufferedwriter, bufferedwriter, created, created, filewriter, printwriter, printwriter, todo

The build.xml source code

<project default="all" xmlns:ac="antlib:net.sf.antcontrib">
    This build file is designed to report the performance
    of ant from various releases.
    to use:
    * install ant-contrib.jar to ($ANT_HOME|$HOME/.ant)/lib
    * install beanshell jar and bsf jar
    * use unix (with bash) or install cygwin
    * set the env variables {whichever needs testing}
      ANT_HOME_6_5 (the directory containing ant 1.6.5)
    * run ant
    For example:
       export ANT_HOME="c:/cygwin/home/me/svn/trunk/dist"
       export ANT_HOME_5_4="l:/apps/apache-ant-1.5.4"

    TODO: more build files.
  <property environment="env"/>

  <target name="all" depends="gen,do-times"/>

  <target name="clean">
    <delete quiet="yes" dir="build"/>

  <macrodef name="run-ant-files">
    <attribute name="env-ant"/>
        <isset property="@{env-ant}"/>
          <ac:shellscript shell="bash">
            export ANT_HOME=${@{env-ant}}
            echo $ANT_HOME
            echo -n "--  props.xml     --: "
            $ANT_HOME/bin/ant -f build/gen/props.xml | grep time
            echo -n "-- ant-call.xml   --: "
            $ANT_HOME/bin/ant -f build/gen/ant-call.xml | grep time
  <target name="do-times">
    <run-ant-files env-ant="env.ANT_HOME"/>
    <run-ant-files env-ant="env.ANT_HOME_6_5"/>
    <run-ant-files env-ant="env.ANT_HOME_6_2"/>
    <run-ant-files env-ant="env.ANT_HOME_5_4"/>

  <target name="gen-dirs">
    <mkdir dir="build/gen"/>

  <target name="avail">
    <available property="avail.props.xml"
               file="props.xml" filepath="build/gen"/>
    <available property="avail.ant-call.xml"
               file="ant-call.xml" filepath="build/gen"/>

  <target name="gen-props" depends="gen-dirs,avail" unless="avail.props.xml">
    <script language="beanshell">
      out = new PrintWriter(new BufferedWriter(new FileWriter(
      out.println("<project name='props' default='props'>");
      out.println("  <target name='props'>");
      for (int i = 0; i < 20000; ++i) {
              "    <property name='prop" + i + "' value='val'/>");
      out.println("  </target>");
      self.log("Created build/gen/props.xml");

  <target name="gen-ant-call" depends="gen-dirs,avail"
    <script language="beanshell">
      out = new PrintWriter(new BufferedWriter(new FileWriter(
      out.println("<project name='ant-call' default='call'>");
      out.println("  <target name='me'/>");
      out.println("  <target name='call'>");
      for (int i = 0; i < 1000; ++i) {
          out.println("    <antcall target='me'/>");
      out.println("  </target>");
      self.log("Created build/gen/ant-call.xml");

  <target name="gen" depends="gen-ant-call,gen-props"/>

Other Ant examples (source code examples)

Here is a short list of links related to this Ant build.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.