Top 27 Apache Ant Interview Questions
Q1. Explain Ant Functionality?
Ant is an open supply task to be had below the Apache license. Therefore, its supply code may be downloaded and modified.
Additionally, Ant makes use of XML build documents which make its improvement easy.
Cross Platform.
Use of XML in conjunction with Java makes Ant makes it the correct solution for developing programs designed to run or be built across a selection of different running systems.
Extensible.
New obligations are used to increase the talents of the construct system, even as construct listeners are used to help hook into the construct method to add extra errors tracking functionality.
As Ant is extensible and open, it could be integrated with any editor or improvement surroundings effortlessly.
Q2. What Is Dependency? How It Is Used Into Ant? What Is Its Use?
Dependencies are do something when complete it. In ant we're the use of dependencies by way of the usage of an attribute “depends” .In this characteristic we have pass values for which the target depends .This mean we first want to execute the goal that's surpassed into this characteristic.
Q3. How We Can Set Path Path And Classpath Into An Ant Build File?
Ant does no longer want to set magnificence route.
Q4. Explain How To Use Pmd Validation In Ant Script?
<target name="validate" depends="-init">
<mkdir dir="$build.Dir/pmd-reports" />
<pmd shortFilenames="true" rulesetfiles="$basedir/.Ruleset">
<formatter type="xml" tofile="$build.Dir/pmd-reports/report.Xml" />
<fileset dir="$src.Dir/main/java/com/" includes="**/*.Java" />
<fileset dir="$src.Dir/test/java" includes="**/*.Java" />
</pmd>
<xslt style="$ant.Home/etc/xslt/pmd-report-per-class.Xslt"
in="$build.Dir/pmd-reports/report.Xml"
out="$build.Dir/pmd-reports/report.Html" />
</target>
Q5. Explain How To Use Ant-contrib Tasks?
Copy the ant-contrib.Jar to the directory ant*/lib. Copy ant-contrib.Jar on your ant*/lib directory.
Append the subsequent code snippet to avail all the ant-contrib duties.
<taskdef resource=”net/sf/antcontrib/antcontrib.Properties”/>
Q6. Explain How To Make Ant User Interactive?
The org.Apache.Gear.Ant.Enter.InputHandler interface is used to put in force the user input. To perform the user enter, the application creates InputRequest object and this item will be exceeded to InputHandler. The user enter can be rejected if it's miles invalid.
The InputHandler interface has precisely one method, by name handleInput(InputRequest request). This technique throws org.Apache.Equipment.Ant.BuildException, if the enter is invalid.
Q7. Why Ant Is A Great Build Tool?
Ant is extremely good build tool due to following reason:
Ant is a Java-primarily based build tool designed to be pass-platform, smooth to apply, extensible, and scalable.
Ant may be used in a small private project in addition to ant may be utilized in a massive, multi-team software program project.
Ant syntax is very clean to study.
Ant syntax used XML format .We need best specifies our mission most effective on build.Xml record.
Ant is easy to use .Disposing of the entire-time make file engineer commonplace on big Make-primarily based software program tasks.
Q8. What Are The Capabilities Of Ant?
ANT device is prolonged by the use of java training. The configuration files are XML-based. Each undertaking of building directory tree is executed by way of the usage of the object that implements the Task interface.
ANT provides the move-platform deployment that may run on any platform.
Q9. Explain Using Ant And Give An Small Example?
Before start using ANT, we need to be clean about the venture name and the .Java files and most significantly, the direction where the .Elegance documents are to be positioned.
For example, we want the application HelloWorld for use with ant. The Java supply files are in a subdirectory referred to as Dirhelloworld, and the .Elegance files are to position into a sub directory called Helloworldclassfiles.
@The construct report via name construct.Xml is to be written. The script is as follows
<project name=”HelloWorld” default=”compiler” basedir=”.”>
<target name=”compiler”>
<mkdir dir = “Helloworldclassfiles”>
<javac srcdir=”Dirhelloworld” destdir=”Helloworldclassfiles”>
</target>
</project>
@Now run the ant script to carry out the compilation:
C :> ant
Buildfile: build.Xml
and see the consequences inside the extra documents and directory created:
c:>dir Dirhelloworld
c:>dir Helloworldclassfiles
All the .Java files are in Dirhelloworld listing and all of the corresponding .Magnificence are in Helloworldclassfiles directory.
Q10. Explain How To Use Runtime In Ant?
There isn't any want to use Runtime in ant. Because ant has Runtime counterpart by using call ExecTask. ExecTask is in the package org.Apache.Tools.Ant.Taskdefs. The Task is created through the usage of the code in the custom designed ant Task. The code snippet is as follows:
ExecTask execTask = (ExecTask)mission.CreateTask (“exec”);
Q11. What Is Different Between Ant And Make?
The most crucial distinction among Ant and Make is that Ant uses XML to explain the construct system and its dependencies, while Make uses its Makefile layout. By default the ant XML file is known as build.Xml.
Q12. How You Can Explain Ant Property?
A venture can have a hard and fast of homes .A assets has name and cost .The name is case sensitive and Properties are immutable this mean as soon as set property its will no longer change. Properties can be used inside the cost of assignment attributes.
Q13. How We Can Create A Jar Using Ant?
To make a jar of lessons we want set target as jar. In this target we need to make directory in which jar will saved. Then we want jar tag to make the jar .In this tag we've got pass two attributes first is call of destination directory and second one is the name of base directory wherein our all class documents are saved .We need a occur to create a jar report. In take place tag we have pass attributes first is call of show up file name and 2d is its fee.
Q14. Explain How To Compile Using Ant Script?
<target name="compile" depends="-init">
<mkdir dir="$build.Dir/classes" />
<javac destdir="$build.Dir/classes" includeantruntime="false" debug="true" optimize="true" verbose="false" deprecation="false" source="1.5" target="1.5">
<classpath refid="classpath.Base" />
<src path="$src.Dir/main/java" />
</javac>
</target>
Q15. What Is A Build Tool?
A constructed tool is software that is used to construct mission, directory shape, copy important files to that directory ,assemble documents ,create jars, set route and sophistication-route ,Build the documentation ,Validate the source code, set up, debug, and run, clear the workspace.
Q16. Explain How To Use Clean In Ant Script?
<target name="clean" depends="-clean" />
<target name="-clean">
<delete dir="$build.Dir/*" />
<delete dir="$build.Dir/classes" />
<delete dir="$build.Dir/test-classes" />
<delete dir="$build.Dir/release" />
<delete file="$build.Dir/*.Jar" />
<delete file="$build.Dir/VERSION.Txt" />
</target>
Q17. How You Can Prepare A Project In Ant?
We can prepare a project via creating a construct.Xml as a construct record and using following tag. Inside this tag we've got described wellknown goals (which includes build, easy and so forth), and so forth.
Q18. Explain How To Import .Jar Files?
<path id="classpath.Base">
<pathelement location="$glassfish.Home/lib/javaee.Jar" />
<fileset dir="$lib.Dir">
<include name="log4j-1.2.15.Jar" />
<include name="el-impl-1.0.Jar" />
</fileset>
</path>
Q19. Explain How To Modify Properties In Ant?
We cannot regulate the homes in ant. The homes in ant are immutable in nature.
Q20. How Can I Use Ant To Run A Java Application?
The following is an example to run a Java application in using ANT:
<target name=”run” depends=”some.Target”,some.Other.Target”>
<java classname=”$run.Class” fork=”yes”>
<classpath>
<path refrid = “classpath” />
</classpath>
<jvmarg line=”$debug.Jvmargs”/>
<jvmarg line=”$my.Jvmargs”/> < BR>
<jvmarg line=”$run.Jvmargs”/>
<arg line=”$run.Args”/>
</java>
</target>
Q21. 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 report characteristic with the filename of the assets record to load.
Setting the url attribute with the url from which to load the houses.
Setting the resource attribute with the resource call of the assets record to load.
Setting the surroundings attribute with a prefix to use.
We can use the combinations of all above in our construct documents .But handiest one should be used at a time.
Q22. Explain How To Debug My Ant Script?
ANT script may be debugged inside the following ways:
By echoing at the region to debug. The problem is without problems known. This is similar to printf() function in C and System.Out.Println() in Java.
By the use of mission.Log (“message”) in the java script or the customized ant task.
By running ANT with –verbose / -debug options. These alternatives offer extra statistics on what's the process going and at which vicinity.
Q23. Explain How To Test Classes For Junit Using Ant Script?
<target name="test" depends="-copytestresources, compile">
<mkdir dir="$build.Dir/junit-reports" />
<junit printsummary="false"
fork="on"
haltonfailure="false"
failureproperty="test.Failure">
<classpath refid="classpath.Junit" />
<formatter type="plain" />
<batchtest todir="$build.Dir/junit-reports">
<fileset dir="$build.Dir/test-classes" includes="**/*Test.Class" />
</batchtest>
</junit>
<junitreport tofile="target/junit-reports/TEST.Xml">
<fileset dir="$target/junit-reports" includes="TEST-*.Xml" />
<report format="frames" todir="$target/junit-reports" />
</junitreport>
</target>
Q24. What Is Ant?
Ant is an open source code .It is Java-based construct device sponsored by way of Apache Software Foundation. It is a software for placing all the pieces of a software together. A easy definition may state that “Ant is a Java-based build tool from Apache Software Foundation”. Ant is sort of like Make.
Q25. What Is Ivy?
Ivy is a popular dependency supervisor .IVY is largely targeted on flexibility and simplicity.
The today's model of Ivy is two.1.Zero.
Key functions of the 2.1.0 release are
The Key features of Ivy is better Maven2 compatibility, with numerous worm fixes and greater pom capabilities included.
New options for the Ivy Ant obligations and commandline
configuration intersections and configuration corporations
numerous bug fixes & improvements as documented in Jira and inside the release notes
Q26. Explain The Concepts Of Ant?
Ant is a build tool this is java based. A construct tool performs the following duties:
Open: Ant is an open supply undertaking to be had below the Apache license. Therefore, its supply code can be downloaded and modified.
Additionally, Ant makes use of XML construct files which make its improvement easy.
Cross Platform: Use of XML together with Java makes Ant makes it the ideal solution for developing packages designed to run or be constructed throughout a variety of different working structures.
Extensible: New tasks are used to extend the capabilities of the construct system, while construct listeners are used to assist hook into the build procedure to feature more errors monitoring capability.
Integration: As Ant is extensible and open, it can be integrated with any editor or improvement environment effortlessly.
Q27. 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 referred to as ANT.
