Ant’s built-in properties – Ant Properties Guide

ants-built-in-properties

This is a simple example that illustrates how to find the basedir name, file name, project name, ant version, java version, operating system name, ant home directory name, java home directory name, user home directory name and user name. Ant provides you with certain built-in properties that you may find useful during your build process. The following table shows the property name and it’s description.

 

Ant’s built-in properties:

Property                                                              Description

 

ant.file                                                                  The absolute path of the build file

 

ant.project.name                                            The name of the project as set in the <project> element’s name attribute.

 

ant.home                                                            The root directory of ant

 

ant.version                                                         The version of this ant installation. This is not just the version number and includes information such as the compilation date.

 

ant.java.version                                               The version of the java that ant uses

 

basedir                                                                 The absolute path of the project

 

os.name                                                              Operating system name

 

java.home                                                          Java home directory name

 

user.home                                                          User directory name

 

user.name                                                          User name                         

 

 

Example Program:

<?xml version=”1.0″?>

 

<project name=”AntProperties” default=”echo” basedir=”.”>

 

  <target name=”echo”>

  <echo message=”The operating system is: ${os.name}”/> 

 

  <!– absolute path of the project. –>

  <echo message=”The home path is: ${basedir}”/>

 

  <!– absolute path of the build file. –>

  <echo message=”The file name is: ${ant.file}”/>

 

  <!– root directory of ant. –>

  <echo message=”The Project name is: ${ant.project.name}”/>

  <echo message=”The Ant home directory is: ${ant.home}”/>

  <echo message=”The Ant version is: ${ant.version}”/>

  <echo message=”The Java version is: ${ant.java.version}”/>

 

  <!– System properties. –>

  <echo message=”The Java home directory is: ${java.home}”/>

  <echo message=”The User home directory is: ${user.home}”/>

  <echo message=”The User name is: ${user.name}”/>

  </target>

 

</project>

 

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

How to Resolve Apache Ant Copy and Include Issues – Ant Guide

issues-in-apache-ant

Question: Why Copy in ant is not working if I am putting includes separately?
Ant version: Apache Ant version 1.5.4 compiled on January 8 2005.

Program 1 is not working and Program 2 is working.  I guess both programs are correct..
Program1:
<copy todir=”${Temp}/uaw/Uaw_compilescripts”>
<fileset dir=”${SVNCheckout}/scripts/compilescripts” >
<include name=”BuildSh,Compsh,vsamc,buildc.sh,script,compl2,main.sh,makefile,makepl1,script”/>

</fileset>
</copy>

Program2:

<copy todir=”${Temp}/uaw/Uaw_compilescripts”>
<fileset dir=”${SVNCheckout}/scripts/compilescripts” includes=”BuildSh,Compsh,vsamc,buildc.sh,script,compl2,main.sh,makefile,makepl1,script” />
</copy>

ANSWER

Because <include name=”> does not split up the name using ‘,’
You need to have :
<include name=”BuildSh”/>
<include name=”Compsh”/>
<include name=”vsamc”/>

etc..

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

Copy and Include Issues in Apache Ant | Ant Troubleshooting Guide

copy-issue-in-apache-ant

Question: Why Copy in ant is not working if I am putting includes separately?

Ant version: Apache Ant version 1.5.4 compiled on January 8 2005.

Program 1 is not working and Program 2 is working.  I guess both programs are correct..

Program1:

      <copy todir=”${Temp}/uaw/Uaw_compilescripts”>

            <fileset dir=”${SVNCheckout}/scripts/compilescripts” >

                  <include name=”BuildSh,Compsh,vsamc,buildc.sh,script,compl2,main.sh,makefile,makepl1,script”/>

                 

            </fileset>

      </copy>

Program2:

     

      <copy todir=“${Temp}/uaw/Uaw_compilescripts”>

            <fileset dir=“${SVNCheckout}/scripts/compilescripts” includes=“BuildSh,Compsh,vsamc,buildc.sh,script,compl2,main.sh,makefile,makepl1,script” />

      </copy>

 

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

Ant command line arguments – Examples – Summary

ant-command-line-arguments

Ant command line arguments
Several tasks take arguments that will be passed to another process on the command line. To make it easier to specify arguments that contain space characters, nested arg elements can be used.

value – a single command-line argument; can contain space characters.
fileThe name of a file as a single command-line argument; will be replaced with the absolute filename of the file.
pathA string that will be treated as a path-like string as a single command-line argument; you can use ; or : as path separators and Ant will convert it to the platform’s local conventions.
pathref Reference to a path defined elsewhere. Ant will convert it to the platform’s local conventions.
line a space-delimited list of command-line arguments.

It is highly recommended to avoid the line version when possible. Ant will try to split the command line in a way similar to what a (Unix) shell would do, but may create something that is very different from what you expect under some circumstances.

Examples
<arg value=”-l -a”/>
is a single command-line argument containing a space character.
<arg line=”-l -a”/>
represents two separate command-line arguments.
<arg path=”/dir;/dir2:\dir3″/>
is a single command-line argument with the value \dir;\dir2;\dir3 on DOS-based systems and /dir:/dir2:/dir3 on Unix-like systems.
Command-line Options Summary
ant [options] [target [target2 [target3] …]]

Options:

-help, -h Displays help information describing the Ant command and its options
-projecthelp, -p Print project help information
-version Print the version information and exit
-diagnostics Print information that might be helpful to diagnose or report problems.
-quiet, -q Suppresses most messages not originated by an echo task in the buildfile
-verbose, -v Displays detailed messages for every operation during a build.
-debug, -d Print debugging information
-emacs, -e Produce logging information without adornments
-lib <path> Specifies a path to search for jars and classes
-logfile <file> Use given file for log
-l <file> Use given file for log
-logger <classname> Specifies a class to handle Ant logging.
-listener <classname> Add an instance of class as a project listener
-noinput Do not allow interactive input
-buildfile <file> Use given buildfile
-file <file> Use given buildfile
-f <file> Use given buildfile
-D<property>=<value> Defines a property name-value pair on the command line.
-keep-going, -k execute all targets that do not depend on failed target(s)
-propertyfile <name> load all properties from file with -D properties taking precedence
-inputhandler <class> the class which will handle input requests
-find <file> Search for buildfile towards the root of the filesystem and use it
Tagged : / / / / / / / / / / / /

What is Apache Ant? – Apache ant Overview

apache-ant

What is an apache ant?
Apache Ant is a Java-based build tool. In theory, it is kind of like Make, but without Make’s wrinkles.

Why another build tool when there is already make, gnumake, nmake, jam, and others?
Because all those tools have limitations that Ant’s original author couldn’t live with when developing software across multiple platforms.
Make-like tools are inherently shell-based — they evaluate a set of dependencies, and then execute commands not unlike what you would issue in a shell. This means that you can easily extend these tools by using or writing any program for the OS that you are working on. However, this also means that you limit yourself to the OS, or at least the OS type such as UNIX, that you are working on.
Makefiles are inherently evil as well. Anybody who has worked on them for any time has run into the dreaded tab problem. “Is my command not executing because I have a space in front of my tab!!!” said the original author of Ant way too many times.
Tools like Jam took care of this to a great degree, but still have yet another format to use and remember.
Ant is different. Instead of a model where it is extended with shell-based commands, Ant is extended using Java classes. Instead of writing shell commands, the configuration files are XML-based, calling out a target tree where various tasks get executed. Each task is run by an object that implements a particular Task interface.
Granted, this removes some of the expressive power that is inherent by being able to construct a shell command such as `find . -name foo -exec rm {}`, but it gives you the ability to be cross platform — to work anywhere and everywhere. And hey, if you really need to execute a shell command, Ant has an task that allows different commands to be executed based on the OS that it is executing on.

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

Running Native Programs in Ant

native-programs-in-ant

Running Native Programs in Ant

Ant, while extremely powerful and flexible, can’t always offer everything you want to do. If this

is the case, you can use the <exec> task, which can run any command-line program.

 The <exec> Task’s Attributes

Attribute Description
appends Sets whether to append the output to the end of a file or overwrite the contents of the file (used in conjunction with output). The default is false.
dir The directory from where the program will be run. The default is null.
error The file to which you want to redirect error messages. The default is the setting in output.
Errorproperty The property where Ant will store error messages. The default is blank.
Executable The command you want to execute. This should be the name of the command and should not be accompanied by any arguments. You specify them with nested <arg> elements. This attribute is required.
failifexecutionfails Tells Ant whether to stop the build if the command fails to start at all. The default is true.
failonerror Tells Ant whether to stop the build if the command exits with a return code other than 0. The default is false.
input The name of a file that will be the input to this command. You can specify only one of input and inputstring. The default is standard input from the console. In addition, you cannot obtain standard input if you set spawn to true.
inputstring A string that will be the input to this command. You can specify only one of input and inputstring. The default is standard input from the console. In addition, you cannot obtain standard input if you set spawn to true.
logError Tells Ant to write error messages to the Ant log files. The error messages will not appear in any output location that you have set. Ant ignores this attribute if you set error or errorproperty. The default is false.
Newenvironment Tells the program to ignore old environment variables if new ones are specified. The default is false.
os Ant will execute the command only if it is running on an operating system in this list. Ant uses String.indexOf() < 0 to see whether the operating system matches anything in this list, so you can specify the operating systems in any format you like, even a continuous string with no separators. The default is to always run the command.
output The file to which you want to redirect output. The default is standard out.
outputproperty The property where Ant will store the output of this command (including error messages unless otherwise redirected). The default is blank.
resolveexecutable Tells Ant to locate the executable in the project’s base directory or the directory specified by dir. The default is false (use the user’s current path).
resultproperty The property where Ant will store the return code of this command. You can use this attribute only if failonerror is false (you’ll find details about this after the table). The default is blank.
searchpath Tells Ant to use the system PATH environment variable to find the command. The default is false.
spawn Tells Ant to start a process that will live after the Ant process has finished. You can’t use error, input, output, or result. The default is false.
timeout The time in milliseconds that Ant should wait before stopping this command. The default is null.
vmlauncher Tells Ant whether to use the JVM’s execution functionality instead of the operating system’s shell. The default is true.
Tagged : / / / / / / / / /