Flow Diagram and GUI tools for Apache Ant


Nurflugel AntScript Visualizer


Ant Script Visualizer is a program I’ve written to make visualizing how your Ant targets and scripts are related to one another.

Ever take a look at an Ant build script and, although perfectly readable, not really “see” all the dependencies between targets?

What targets depend on a certain taskdef? Or a macrodef? Do macrodefs rely on other macrodefs? And all those imported Ant scripts – where do they fit in? This program was designed to show that, by importing your Ant scripts and creating graphic file representations of them. Say what?

OK, here’s an example of the output for the build file used for this program:

# Parses build files for the following task usages:

* target
* ant
* antcall
* depends
* property
* import
* taskdef
* macrodef

# Groups results by build file subgraphs (default), or optionally, all items together in one graph
# Ability to filter/show included obects by target, imported files, ant calls, taskdefs, and macrodefs
# Output formats: PNG (default for PC), PDF (default for OS X, not available otherwise), SVG.



Grand is a tool to create visual representation of ant target dependencies. It differs from tools like Vizant or AntGraph  by a totally different approach, relying on the Ant API rather than parsing directly the XML files. This enables Grand to provide some nifty features such as the support of the ant 1.6.x tasks like import or subant.




Vizant is an Apache Ant task to create Graphviz DOT source code from an Ant buildfile. The image created from the DOT source code shows the targets dependency.

Tagged : / / / / / / / / / / / / / / /

Usage of ANT_OPTS in Ant Script | ANT_OPTS capabilities


Usage of ANT_OPTS in Ant Script | ANT_OPTS capabilities

Ant has three environment variables that you can use to set its default behavior.
• ANT_ARGS Set this variable to include those options you use frequently.
• ANT_OPTS is a list of arguments that you want to pass to the JVM that will run Ant.
• JAVACMD is the absolute path to the Java executable you want Ant to use. you may specify a value for the JAVACMD environment variable. This defaults to %JAVA_HOME%\bin\java, typically invoking the JVM provided in Sun’s Java Development Kit. Ant provides JAVACMD for those who wish to specify an alternate JVM. full path of the Java executable. Use this to invoke a different JVM than JAVA_HOME/bin/java(.exe).

These are useful environment variables that the Ant wrapper scripts use when
invoking Ant: ANT_OPTS and ANT_ARGS. Neither of these is typically set by users,
but each can provide value for certain situations.

The ANT_OPTS environment variable provides options to the JVM executing Ant,
such as system properties and memory configuration. ANT_OPTS – command-line arguments that should be passed to the JVM. For example, you can define system properties or set the maximum Java heap size here.

For authenticated proxy:
Set your ANT_OPTS environment variable to configure your proxy if you have one. For instance:
set ANT_OPTS=-Dhttp.proxyHost=myproxy -Dhttp.proxyPort=3128

You can set these properties by either modifying Ant’s startup script, or by
using the ANT_OPTS environment variable. The following example shows the Windows commands to specify these properties using ANT_OPTS, and then to invoke Ant:
set ANT_OPTS=-DproxySet=true -DproxyHost=localhost -DproxyPort=80
ant mytarget
The same trick works on Unix, although the syntax is slightly different depending on which
shell you use:
$ export ANT_OPTS=”-DproxySet=true -DproxyHost=localhost -DproxyPort=80″
$ ant mytarget

set ANT_OPTS=-Dhttp.proxyHost=myproxyhost -Dhttp.proxyPort=8080 -Dhttp.proxyUserName=myproxyusername -Dhttp.proxyPassword=myproxypassword -Dhttps.proxyHost=myproxyhost -Dhttps.proxyPort=8080


Use ANT_OPTS to control Ant’s virtual machine settings.
Some tasks may require more memory, which you can set in the ANT_OPTS environment variable, using the appropriate mechanism for your platform:
set ANT_OPTS=-Xmx500M
export ANT_OPTS=-Xmx500M

Setting the maximum heap size is another common use of ANT_OPTS. Here is how we set the maximum size to 128 MB when using Sun’s JDK:
set ANT_OPTS=-Xmx128m

One environment variable you may wish to set is ANT_OPTS. The value of this variable is passed as a JVM argument. Specifying system properties is a common use. In this simple
example, we pass the log.dir system property to the JVM running Ant:
$ set ANT_OPTS=-Dlog.dir=C:\logs
$ ant run
Now this property is available within the buildfile, for instance:
<echo>Log directory is set to: ${log.dir}</echo>
If the buildfile runs a Java application, the property may be retrieved from within it as
String logDir = System.getProperty(“log.dir”);


Troubleshoot: Illegal Java options in the ANT_OPTS variable
The environment variable ANT_OPTS provides a means to pass options into Ant,
such as a permanent definition of some properties, or the memory parameters for
Java. The variable must contain only options the local JVM recognizes. Any invalid
parameter will generate an error message such as the following (where ANT_OPTS was
set to –3):
Unrecognized option: -3
Could not create the Java virtual machine.

If the variable contains a string that is mistaken for the name of the Java class to run
as the main class, then a different error appears:

Exception in thread “main” java.lang.NoClassDefFoundError: error-string
Test: Examine ANT_OPTS and verify that the variable is unset or contains valid
JVM options.
Fix: Correct or clear the variable.

Tagged : / / / / / / / / / / / / / / /

How to use ant Script to Reset BuildNumber?

To use this code, you need to have the file build.number containging:




Then the following 3 targets:

  <taskdef resource=”net/sf/antcontrib/antlib.xml”/>
<taskdef name=”unset” classname=”ise.antelope.tasks.Unset”/>

    <target name=”initBuildNum” description=”Get current build number properties”>
<property file=”build.number”/>
<var name=”next.major” value=”${major.number}”/>
<var name=”next.minor” value=”${minor.number}”/>
<var name=”next.hotfix” value=”${hotfix.number}”/>
<var name=”next.revision” value=”${revision.number}”/>
<var name=”next.continuous” value=”${continuous.number}”/>

    <target name=”getBuildNum”>
<switch value=”${increment}”>
<case value=”rebuild”/>
<case value=”major”>
<!–Increment major, minor to 1, hotfix to 0, revision to 1–>
<math result=”next.major” operand1=”${next.major}” operation=”+” operand2=”1″ datatype=”int”/>
<var name=”next.minor” value=”1″ />
<var name=”next.hotfix” value=”0″ />
<var name=”next.revision” value=”1″ />
<case value=”minor”>
<!–Major stays the same, minor increments, hotfix goes to 0, revision to 1–>
<math result=”next.minor” operand1=”${next.minor}” operation=”+” operand2=”1″ datatype=”int”/>
<var name=”next.hotfix” value=”0″ />
<var name=”next.revision” value=”1″ />
<case value=”hotfix”>
<!–Major stays the same, minor stays the same, hotfix increments, revision goes to 1–>
<math result=”next.hotfix” operand1=”${next.hotfix}” operation=”+” operand2=”1″ datatype=”int”/>
<var name=”next.revision” value=”1″ />
<case value=”continuous”>
<!–For continuous integration don’t change anything but 5th build digit–>
<math result=”next.continuous” operand1=”${next.continuous}” operation=”+” operand2=”1″ datatype=”int”/>
<case value=”contReset”>
<!–Continuous build, but they want the 5th digit reset (i.e. new week)–>
<var name=”next.continuous” value=”1″/>
<!–Update revision number only, they didn’t ask for anything special–>
<math result=”next.revision” operand1=”${next.revision}” operation=”+” operand2=”1″ datatype=”int”/>

    <target name=”setBuildNumber” depends=”initBuildNum,getBuildNum”>
<!–First save the build number properties–>
<propertyfile file=”build.number”>
<entry key=”major.number” value=”${next.major}”/>
<entry key=”minor.number” value=”${next.minor}”/>
<entry key=”hotfix.number” value=”${next.hotfix}”/>
<entry key=”revision.number” value=”${next.revision}”/>
<entry key=”continuous.number” value=”${next.continuous}”/>
<!–Unset the properties so that we can change their values–>
<unset name=”major.number”/>
<unset name=”minor.number”/>
<unset name=”hotfix.number”/>
<unset name=”revision.number”/>
<unset name=”continuous.number”/>
<property file=”build.number”/>
<!–set the full.buildnumber property to be used by the build–>
<equals arg1=”${increment}” arg2=”continuous”/>
<equals arg1=”${increment}” arg2=”contReset”/>
<property name=”full.buildnumber” value=”${major.number}.${minor.number}.${hotfix.number}.${revision.number}.${continuous.number}”/>
<property name=”full.buildnumber” value=”${major.number}.${minor.number}.${hotfix.number}.${revision.number}”/>

Add these three targets to your ant script.  Put a “depends” to “setBuildNumber” at invocation of your ant script.  Depending on what you want to do, you’ll set different vars on the way in as follows:

To build and increment revision number only:
To move to the next major build number:
>Ant -Dincrement=major
To move to the next minor build number:
>Ant -Dincrement=minor
To move to the next hotfix build number:
>Ant -Dincrement=hotfix

  To do a continuous integration build incrementing 5th digit:
>Ant -Dincrement=continuous
To do a continuous integration build resetting 5th digit to 1:
>Ant -Dincrement=contReset

Note that if you don’t set the value of increment, the build number will only have 4 digits.  The var that holds the build number after this is called is ${full.buildnumber}.

Tagged : / / / / / / / / / / / / / / / /

Ant Script with Shell script, How to run shell script from Ant Script?


Ant Script with Shell script
How to set files Permission in Ant | How to set files Permission in Unix | Set files Permission in Ant in Unix Environment


Ant Script to Replace some character in any files


How to run shell script using ant/
To Remove Some Special Character from Files
for name in `find PWD -type f`
if [ -f $name ]; then
tr -d “\015” ${name}XXXYYYZZZ
mv ${name}XXXYYYZZZ $name
echo “$name updated”


Tagged : / / / / / / / / / / /