ANT interview questions for fresher/ANT Interview Questions and Answers for Freshers & Experienced

What is 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.

Explain How To Use Ant-contrib Tasks?

Copy the ant-contrib.Jar to the listing ant*/lib. Copy ant-contrib.Jar for your ant*/lib listing.
Append the following code snippet to avail all the ant-contrib tasks.
<taskdef resource=”net/sf/antcontrib/antcontrib.Properties”/>

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>

How We Can Set Path Path And Classpath Into An Ant Build File?

Ant does now not want to set elegance course.

What Is Ivy?

The latest model of Ivy is two.1.Zero.Key functions of the two.1.Zero release areThe Key functions of Ivy is superior Maven2 compatibility, with several malicious program fixes and greater pom capabilities blanketed.
New alternatives for the Ivy Ant tasks and commandline
configuration intersections and configuration organizations
severa computer virus fixes & enhancements as documented in Jira and inside the launch notes

What Is Different Between Ant And Make?

The maximum important distinction between Ant and Make is that Ant uses XML to explain the build method and its dependencies, while Make makes use of its Makefile format. By default the ant XML report is called construct.Xml.

How We Can Create A Jar Using Ant?

To make a jar of training we want set goal as jar. In this goal we need to make directory in which jar will saved. Then we need jar tag to make the jar .In this tag we've got pass attributes first is name of destination listing and 2nd one is the call of base directory in which our all magnificence files are stored .We want a occur to create a jar document. In occur tag we have pass two attributes first is name of take place report call and 2nd is its cost.

What Is Dependency? How It Is Used Into Ant? What Is Its Use?

Dependencies are do some thing while whole it. In ant we are the usage of dependencies with the aid of the usage of an attribute “relies upon” .In this attribute we've pass values for which the target depends .This mean we first want to execute the target which is handed into this attribute.

How Many Ways We Can Set Properties Into Build Ant File?

There are six approaches to set houses:Supplying both the call and cost attribute.<property name=”src.Dir” value=”src”/>
Supplying each the call and refid characteristic.
Setting the report characteristic with the filename of the assets document to load.
Setting the url attribute with the url from which to load the homes.
Setting the resource characteristic with the resource call of the property document to load.
Setting the surroundings characteristic with a prefix to use.
We can use the mixtures of all above in our build documents .But handiest one need to be used at a time.

Why Ant Is A Great Build Tool?

Ant is extraordinary build device because of following reason:Ant is a Java-primarily based construct tool designed to be move-platform, easy to use, extensible, and scalable.
Ant may be utilized in a small private undertaking in addition to ant can be utilized in a big, multi-group software program undertaking.
Ant syntax may be very smooth to study.
Ant syntax used XML format .We need only specifies our project handiest on construct.Xml file.
Ant is straightforward to use .Getting rid of the overall-time make report engineer not unusual on big Make-based software program initiatives.

How to let auto-detect platform and use platform specific properties?

Tell you a great trick, it works excellent.
In your major build-include.xml, put in this line

<property file="${antutil.includes}/${os.name}-${os.arch}.properties" />

This will auto-detect your platform, and you write one file for each environment specific variables. For example: HP-UX-PA_RISC2.0.properties SunOS-sparc.properties Windows XP-x86.properties

Can I change/override ant properties when I use ant-contrib foreach task?

<foreach> is actually using a different property space, you can pass any property name/value pair to it. Just use <param> nested tag inside foreach.

How to do conditional statement in ant?

There are many ways to solve the problem.

<> Since target if/unless all depend on some property is defined or not, you can use condition to define different NEW properties, which
in turn depends on your ant property values. This makes your ant script very flexible, but a little hard to read.

<> Ant-contrib has <if> <switch> tasks for you to use.

<> Ant-contrib also has <propertyregex> which can make very complicate decisions.

How do I add elements to an existing path dynamically?

Yes, it is possible. However, you need to write a custom ant task, get the path, and add/modify it, and put it in use. What I am doing is that I define a path reference lib.classpath, then add/modify the lib.classpath use my own task.

How to hide password input?

Override ant Input task.
Response every user input with a backspace. Not the best, but it works

Can you give me a simple ant xslt task example?

Here is a working one!

<xslt style="${xslfile}" in="${infile}" out="${outfile}" >

<classpath>

<fileset dir="${xml.home}/bin"

includes="*.jar" />

</classpath>

</xslt>

How to pass -Xlint or -Xlint:unchecked to 1.5 javac task?

pass it as compilerarg nested <compilerarg> to specify.

<compilerarg value="-Xlint"/>

<!-- or -->

<compilerarg value="-Xlint:unchecked"/>

How do I use two different versions of jdk in ant script?

The followings are what I’m doing.

Don’t define java.home by yourself. Ant uses an internal one derived from your environment var JAVA_HOME. It is immutable.
I do the followings:
* In my build.properties (read first)

jdk13.bin=${tools.home}/jdk1.3.1_13/bin

jdk14.bin=${tools.home}/j2sdk1.4.2_08/bin/

* In my master properties file (read last), set default

javac.location=${jdk13.bin}

* In my prj.properties, if I need to use 1.4

javac.location=${jdk14.bin}

* in my javac task

executable=”${javac.location}/javac.exe”

How to copy files without extention?

If files are in the directory:

<include name="a,b,c"/>


If files are in the directory or subdirectories:

<include name="**/a,**/b,**/c"/>

If you want all files without extension are in the directory or subdirectories:

<exclude name="**/*.*"/>

How can I write my own ant task?

Writing Your Own Task How-To from ant.
In your own $ANT_HOME/docs/manual directory, there also is tutorial-writing-tasks-src.zip

Use them! Use taskdef to define it in your script, define it before using it.

Why did I get such warning in ant?

[javac] Warning: commons-logging.properties modified in the future.

[javac] Warning: dao\DAO.java modified in the future.

[javac] Warning: dao\DBDao2.java modified in the future.

[javac] Warning: dao\HibernateBase.java modified in the future.

System time problem, possible reasons:

<> You changed the system time.

<> I had the same problem before, I checked out files from cvs to windows, and transfer them to a unix machine, somehow, I got huge amount of such warnings because the system timing issue.

<> If you transfer files from Australia/China/india to the United States, you will get the problem too. True enough, I did and met the
problem once.

How to rearrange my directory structure in my jar/war/ear/zip file? Do I
need to unarchive them first?

<> You don’t need to unzip the files from archive to put into your destination jar/ear/war files.

<> You can use zipfileset in your jar/war/ear task to extract files from old archive to different directory in your new archive.

<> You also can use zipfileset in your jar/war/ear task to send files from local directory to different directory in your new archive.

How to use Runtime in ant?

You don’t need to use Runtime etc. Ant have exec task.
The class name is org.apache.tools.ant.taskdefs.ExecTask. You can create the task by using the code in your customized ant Task.

ExecTask compile = (ExecTask)project.createTask(“exec”);

How do I debug my ant script?

1. Do an echo on where you have doubt. You will find out what is the problem easily. Just like the old c printf() or Java System.println().
2. Use project.log(“msg”) in your javascript or custom ant task.
3. Run Ant with -verbose, or even -debug, to get more information on what it is doing, and where. However, you might be tired with
that pretty soon, since it give you too much information.

How to use ant to run commandline command? How to get perl script running result?

Use exec ant task.

Don’t forget ant is pure Java. That is why ant is so useful, powerful and versatile. If you want ant receive unix command and result, you must think Unix. So does in MS-Windows. Ant just helps you to automate the process.

How can I use ant to run a Java application?

Here is a real world example.

<target name="run" depends="some.target,some.other.target">

<java classname="${run.class}" fork="yes">
<classpath>
<path refid="classpath" />
</classpath>
<jvmarg line="${debug.jvmargs}" />

<jvmarg line="${my.jvmargs}" />
<jvmarg value="-Dname=${name}" />
<jvmarg line="${run.jvmargs}" />

<arg line="${run.args}" />

</java>

</target>

Where can I find the javadoc for ant API?

Download apache ant src version. Use ant javadocs command to see generated javadoc for ant in build/docs directory.

Can I put the contents of a classpath or fileset into a property?

This is very similar to the call of Java class toString() method and actually it is calling the toString() method inside ant. For example


<fileset id="fs1" dir="t1" includes="**/*.java"/>

<property name="f1.contents" refid="fs1"/>

<echo>f1.contents=${f1.contents}</echo>

Why do I get en exception when I use location=”D:\Code\include” as
attribute of includepath?

You need to escape the string to “D:\\Code\\include” or use “D:/Code/include” instead!

Believe me or not? Forward slash works on windows in all ant or java code. It also works in windows environment variables. It does not work in cmd (dos) window before XP. It also works in XP dos window now!

How to loop on a list or fileset?

Use ant-contrib <for> <foreach> tasks

General to say, use <for> is better than use <foreach> since for each is actually open another ant property space, use more memory too.

How to use ant-contrib tasks?

A: Simple, just copy ant-contrib.jar to your ant*/lib directory

And add this line into your ant script, all ant-contrib tasks are now available to you!
<taskdef
resource=”net/sf/antcontrib/antcontrib.properties” />

How to modify properties in ant?

No, you can’t!

Properties in Ant are immutable. There is a good reason behind this, see this FAQ item for more details.

How does ant read properties? How to set my property system?

Ant sets properties by order, when something is set, the later same properties cannot overwrite the previous ones. This is opposite to your Java setters. This give us a good leverage of preset all properties in one place, and overwrite only the needed. Give you an example here. You need password for a task, but don’t want to share it with your team members, or not the developers outside your team.

Store your password in your ${user.home}/prj.properties

pswd=yourrealpassword

In your include directory master prj.properties

pswd=password

In your build-common.xml read properties files in this order

1. The commandline will prevail, if you use it: ant -Dpswd=newpassword
2. ${user.home}/prj.properties (personal)
3. yourprojectdir/prj.properties (project team wise)
4. your_master_include_directory/prj.properties (universal)

<cvsnttask password="${pswd} ... />

How to use ant to run commandline command? How to get perl script running result?

Use exec ant task.

Don’t forget ant is pure Java. That is why ant is so useful, powerful and versatile. If you want ant receive unix command and result, you must think Unix. So does in MS-Windows. Ant just helps you to automate the process.

Can I put the contents of a classpath or fileset into a property?

Yes, you can.

This is very similar to the call of Java class toString() method and actually it is calling the toString() method inside ant. For example

<fileset id=”fs1″ dir=”t1″ includes=”**/*.java”/>
<property name=”f1.contents” refid=”fs1″/>
<echo>f1.contents=${f1.contents}</echo>

How to use ant-contrib tasks?

Simple, just copy ant-contrib.jar to your ant*/lib directory
And add this line into your ant script, all ant-contrib tasks are now available to you!

<taskdef
resource=”net/sf/antcontrib/antcontrib.properties” />

Explain How To Use Runtime In Ant?

There is no need to use Runtime in ant. Because ant has Runtime counterpart by name ExecTask. ExecTask is in the package org.apache.tools.ant.taskdefs. The Task is created by using the code in the customized ant Task. The code snippet is as follows:

ExecTask execTask = (ExecTask)project.createTask (“exec”);

Explain How To Make Ant User Interactive?

The org.apache.tools.ant.input.InputHandler interface is used to implement the user input. To perform the user input, the application creates InputRequest object and this object will be passed to InputHandler. The user input will be rejected if it is invalid.

The InputHandler interface has exactly one method, by name handleInput(InputRequest request). This method throws org.apache.tools.ant.BuildException, if the input is invalid.

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.

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.

What Are The Capabilities Of Ant?

ANT tool is extended by using java classes. The configuration files are XML-based. Each task of building directory tree is executed by using the object that implements the Task interface.

ANT provides the cross-platform deployment that can run on any platform.

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.

List some basic functions performed by Ant.

Ant tool is used for:-

1. Compiling Java code into bytecode
2. Placing this bytecode in a package
3. Deployment to production systems
4. Document creation and release notes preparation.

What is Apache Ant?

Apache Ant is a Java library and command-line tool for automating software build processes.It drives the processes or instructions described in build files as targets and extension points dependent upon each other.The main known usage of Ant is the build of Java applications. Ant supplies a number of built-in tasks allowing to compile, assemble, test and run Java applications. Ant can also be used effectively to build non Java applications, for instance C or C++ applications. More generally, Ant can be used to pilot any type of process which can be described in terms of targets and tasks.

Search
R4R Team
R4R provides ANT Freshers questions and answers (ANT Interview Questions and Answers) .The questions on R4R.in website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,ANT interview questions for fresher,ANT Freshers & Experienced Interview Questions and Answers,ANT Objetive choice questions and answers,ANT Multiple choice questions and answers,ANT objective, ANT questions , ANT answers,ANT MCQs questions and answers Java, C ,C++, ASP, ASP.net C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for ANT fresher interview questions ,ANT Experienced interview questions,ANT fresher interview questions and answers ,ANT Experienced interview questions and answers,tricky ANT queries for interview pdf,complex ANT for practice with answers,ANT for practice with answers You can search job and get offer latters by studing r4r.in .learn in easy ways .