What is Ant?
Ant stands for Another Neat Tool. It is an open source code .It is Java-based build tool sponsored by Apache Software Foundation. It is a program for putting all the pieces of a program together. A simple definition might state that “Ant is a Java-based build tool from Apache Software Foundation”.
Can you explain Ant functionality?
Ant is an open source project available under the Apache license. Therefore, its source code can be downloaded and modified.
Additionally, Ant uses XML build files which make its development easy.
Cross Platform: Use of XML along with Java makes Ant makes it the perfect solution for developing programs designed to run or be built across a range of different operating systems.
Extensible: New tasks are used to extend the capabilities of the build process, while build listeners are used to help hook into the build process to add extra error tracking functionality.
As Ant is extensible and open, it can be integrated with any editor or development environment easily.
Can you define build tool?
A built tool is software which is used to build project, directory structure, copy necessary files to that directory ,compile files ,create jars, set path and class-path ,Build the documentation ,Validate the source code, deploy, debug, and run, clear the workspace.
How we can deploy file on server using ant?
<?xml version=”1.0″ ?>
<project name=”ProjectName” default=”deploy”>
………………
…………….
<target name=”deploy” depends=”compile,doc” >
<jar destfile=”dist/project.jar”
basedir=”build/classes”/>
<ftp server=”${server.name}”
userid=”${ftp.username}”
password=”${ftp.password}”>
<fileset dir=”dist”/>
</ftp>
</target>
…………
……..
</project>
What are the Core Concepts of Ant?
The core concepts of Ant as
XML format: Ant uses XML files called build files to describe how to build, test, and deploy an application
Declarative syntax: Ant is declarative. Rather than spelling out the details of every stage in the build process
A build file contains one project: Each XML build file includes how to build, test, and deploy one project. Very large projects may be composed of multiple smaller projects, each with its own build file. A higher-level build file can coordinate the builds of the subprojects.
Each project contains multiple targets: Within the single project of a build file, you declare the different targets for the build process. These targets may represent actual outputs of the build, such as a redistributable file, or stages in the build process, such as compiling source or deploying the redistributable file to a remote server.
Targets can have dependencies on other targets: When declaring a target, you can declare which targets have to be built first. This ensures that the source gets compiled before the redistributables are built, and that the redistributable is built before the remote deployment.
Targets contain tasks: Inside targets you declare what actual work is needed to complete that stage of the build process. You do this by listing the tasks that constitute each stage. Each task is actually a reference to a Java class, built into Ant or an extension library, which understands the parameters in the build file and can execute the task based upon the parameters. These tasks are expected to be smart—to handle much of their own argument validation, dependency checking, and error reporting.
New tasks can easily be added in Java: The fact that it is easy to extend Ant with new classes is one of its core strengths
Why Ant is a great build tool?
Ant is great build tool due to following reason:
- Ant is a Java-based build tool designed to be cross-platform, easy to use, extensible, and scalable.
- Ant can be used in a small personal project as well as ant can be used in a large, multi-team software project.
- Ant syntax is very easy to learn.
- Ant syntax used XML format .We need only specifies our task only on build.xml file.
- Ant is easy to use .eliminating the full-time make file engineer common on large Make-based software projects.
- It Hadlee’s Java class-paths and file directory structure in a portable manner. It hand’s it as cross-platform.
- Ant is very fast.Java routines such as compiler or code make a jar file can start inside the Ant JVM. This reduce process of startup delay .Ant tasks are also designed to do dependency checking to avoid doing any more work than necessary.
- Ant integrate tightly with the JUnit test frameworks for XP-style using testing.
- An Ant is easily extensible using Java.
- Ant Ant has built-in support for J2EE development, Such as EJB compilation and packaging.
- Ant addresses the deployment problems of Java project such as FTP, Telnet, application servers, SQL commands; all can used for automated deployment.
- Ant is the de facto standard (is a standard formal or informal) for most open source Java projects,Such as Apache Tomcat and Apache Xerces. Many application servers even ship with embedded version of Ant for deployment.
- As Ant understands testing and deployment, I can be used for a unified build-test-deploy process, by a single command or by use of Ant-aware Java IDE, such as NetBeans, Eclipse IDEA, and jEdit.
- Ant can be used to control team works together to build and deploy Java project easily.
What is IVY? What are the key features of 2.5.0?
Ivy is a popular dependency manager .IVY is basically focused on flexibility and simplicity.
The latest version of Ivy is 2.5.0.
Key features of ivy 2.5.0:
The minimum runtime Java version required is now Java 7
Ivy now uses BouncyCastle OpenPGP API 1.59. Due to the non backward compatibility of that library, earlier versions are not supported.
Ivy now uses HttpComponents HttpClient 4.5.x version with HTTP backed resolvers. Users are expected to have this version of the library (and its dependencies) in their runtime classpath if they want to use such resolvers. The previous (similarly named but not the same) commons-httpclient library is no longer used or supported. (IVY-1563)
What is advantage of Ant 1.7.1?
- Ant 1.7.1 is mainly a bugfix release.
- Ant 1.7.1 has extended support for Java6 features.
- Ant 1.7.1 <script> now has support for JavaFX.
How we can set path PATH and CLASSPATH into an ant build file?
Ant does not need to set classpath.
What is Built-in Properties? And how many Built-in Properties?
Ant provides access to all system properties .This system properties build –in property is used as they had been defined using a <property> task. E.g, ${os.name} is used to get the os name.
Ant has some main built-in properties:
- Basedir:This gives the absolute path of the project’s basedir
- file:The absolute path of the build file.
- version:The version of Ant
- project.name:The name of the project executing;
- java.version:The JVM version Ant detected
- home:This is used to get home directory of Ant.
How many ways we can set properties into build ant file?
There are six ways to set properties:
- Supplying both the name and value attribute.
- <property name=”src.dir” value=”src”/>
- Supplying both the name and refid attribute.
- Setting the file attribute with the filename of the property file to load.
- Setting the url attribute with the url from which to load the properties.
- Setting the resource attribute with the resource name of the property file to load.
- Setting the environment attribute with a prefix to use.
We can use the combinations of all above in our build files .But only one should be used at a time.
How we can echo message in Ant?
We need to use <echo> tag to print message on ant consol. We can use following syntax to print message on ant command prompts.
<project>
………
………
<property name=”classes.dir” value=”classes”/>
<echo>$${builddir}=${classes.dir}</echo>
……………
……………
</project>
The output will be :${builddir}=classes
Note: To echo $$ use $$$$.
How you can explain ant property?
A project can have a set of properties .A property has name and value .The name is case sensitive and Properties are immutable this mean once set property its will not change. Properties may be used in the value of task attributes. We can use it by placing name of properties within ${ } in the attribute values.
e.g.
<project>
…..
…..
<property name=”classes.dir” value=”classes”/>
<target name=”clean” description=”Delete all generated files”>
<delete dir=”${classes.dir}” />
</target>
….
….
</project>
What is dependency? How it is used into ant?
Dependencies are do something when complete it. In ant we are using dependencies by using an attribute “depends” .In this attribute we have pass values for which the target depends .This mean we first need to execute the target which is passed into this attribute.
e.g. In this example we are passing depends=” clean, compile”. This instruct ant first clean and compile target will executed then clean-build target will executed.
<project>
. . . .
. . . .
<target name=”clean”>
<delete dir=”${build.dir}”/>
</target>
<target name=”compile”>
<mkdir dir=”${classes.dir}”/>
<javac srcdir=”${src.dir}” destdir=”${classes.dir}”/>
</target>
<target name=”clean-build” depends=”clean,compile”/>
……..
</project>
How you can compile, jar and run into ant command prompt?
We can compile, package (create jar) and run the application via ant by using following syntax into command prompt
- ant compile
- ant jar
- ant run
Or we can use following as short cut
ant compile jar run
How we can run jar using Ant?
To run a jar we need to create a target with the name of run. In this target we need to pass <java> which is used to instruct ant to run application. In this tag we have pass two attributes first is name of jar file with exact location and second is fork=”true” or fork=”false”. The fork=”true mean run into different JVM. The Syntax will be as following:
<project>
…… …..
<target name=”run”>
<java jar=”build/jar/Test.jar” fork=”true” /> </target>
……. …….
</project>
How we can create a jar using Ant?
To make a jar of classes we need set target as jar. In this target we need to make directory in which jar will stored. Then we need jar tag to make the jar .In this tag we have pass two attributes first is name of destination directory and second one is the name of base directory where our all class files are stored .We need a manifest to create a jar file. In manifest tag we have pass two attributes first is name of manifest file name and second is its value.
The Syntax will be as following:
<project>
……
…..
<target name=”jar”>
<mkdir dir=”build/jar” />
<jar destfile=”build/jar/Test.jar” basedir=”build/classes”>
<manifest >
<attribute name=”Main-Class” value=”r4r.Test”>
</manifest>
</jar>
</target>
…….
…….
</project>
How we can set compile target using Ant?
To compile java application we need to create a target with the name of “compile”. In this target we need to make a directory where we have to store all the .class files after compile .Ant have a <javac> tag to compile the java files .In this tag we need to pass two attributes first is destination where we have to store all .class files and other is source directory where all source files are stored.
The Syntax will be as following:
<project>
……
…..
<target name=”compile”>
<mkdir dir=”build/classes”>
<javac srcdir=”src” destdir=”build/classes”>
</target>
…….
…….
</project>
How you can clean or delete workspace using Ant?
To clear or delete workspace we need to make a target with name clear .Into this target we are using delete tag and set the name of dir=”build” .Here “build” is the name of workspace which we have delete or clear .
The Syntax will be as following:
<project>
……
…..
<target name=”clean”>
<delete dir=”build”/>
</target>
…….
…….
</project>
How we can set the PATH environment variable of Ant?
Assume Ant is installed in d:\ant\.
The following sets up the environment:
Set environment for Windows and OS/2
set ANT_HOME=d:\ant
set JAVA_HOME=d:\jdk-1.5.0.05
set PATH=%PATH%;%ANT_HOME%\bin
Set environment for Linux/Unix (bash)
Assume Ant is installed in /usr/local/ant. The following sets up the environment:
export ANT_HOME=/usr/local/ant
export JAVA_HOME=/usr/local/jdk-1.5.0.05
export PATH=${PATH}:${ANT_HOME}/bin
Set environment for Linux/Unix (csh)
setenv ANT_HOME /usr/local/ant
setenv JAVA_HOME /usr/local/jdk/jdk-1.5.0.05
set path=( $path $ANT_HOME/bin )
How you can prepare a project in Ant?
We can prepare a project by making a build.xml as a build file and using following tag. Inside this tag we have defined standard targets (such as build, clean, etc),etc.
<project name=”NameOfProject” basedir=”.” default=”main”>
………
……..
</project>
Why do you call it Ant?
The ant is acronym of \”Another Neat Tool\” according to James Duncan Davidson. Ants are very small and can carry heavy weight.So as Job of Apache ant. Its name is called ANT.
Which version of Java is required to run Ant?
The following table lists the minimum Java versions required to compile and run Ant:
Ant Version Minimum Java Version
1.1 To 1.5.4 1.1
1.6.0 To 1.6.5 1.2
1.7.0 To 1.7.1 1.3
Svn trunk 1.4
The Ant v1.9.x releases require Java5 at runtime and 1.10.x requires Java8 at runtime. Both lines are based off of Ant 1.9.7 and the 1.9.x releases are mostly bug fix releases while additional new features are developed for 1.10.x. We recommend using 1.10.x unless you are required to use versions of Java prior to Java8 during the build process.
What is History of Ant?
Ant was created by James Duncan Davidson (author of Tomcat). Initially, It was part of the Tomcat .When it was donated to the Apache Software Foundation. Ant was used to build Tomcat, nothing else. But In January 2000, Ant was moved to a separate CVS module and was promoted to a project of its own, independent of Tomcat, and became Apache Ant.
The first version of Ant was the one that shipped with Tomcat’s 3.1 releases on 19 April 2000. This version was referred as Ant 0.3.1 later.
The version of ant is released at 27 June 2008 is Ant1.7.1.
What is different between Ant and Make?
The most important difference between Ant and Make is that Ant uses XML to describe the build process and its dependencies, whereas Make uses its Make file format. By default the ant XML file is named build.xml.
How many types of build tool you know?
I know two type of build tool which are used to build a java based project.
These are ANT and Make.