<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JavaBeat &#187; Apache Ant</title>
	<atom:link href="http://www.javabeat.net/category/tools-ides/apache-ant/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javabeat.net</link>
	<description>Java Technology News</description>
	<lastBuildDate>Thu, 23 May 2013 01:30:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Apache Ant Interview Questions</title>
		<link>http://www.javabeat.net/2010/08/apache-ant-interview-questions/</link>
		<comments>http://www.javabeat.net/2010/08/apache-ant-interview-questions/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 00:40:19 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Apache Ant]]></category>
		<category><![CDATA[Interview Questions]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=454</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Apache Ant Interview Questions &#8211; 1 1)What is ant? Ant is a small animal who can build magnificent buildings. Ant builds! ANT is a Java based building tool, which is similar to make, and so much better than make. ANT, what a smart name for a building tool, even the original author of ANT, James [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><a id="dd_start"></a><h2>Apache Ant Interview Questions &#8211; 1</h2>
<h3>1)What is ant?</h3>
<p>Ant is a small animal who can build magnificent buildings. Ant builds! ANT is a Java based building tool, which is similar to make, and so much better than make. ANT, what a smart name for a building tool, even the original author of ANT, James Duncan Davidson, meant &#8220;Another Neat Tool&#8221;. A win-win ant learning method</p>
<p>There is a shortcut.</p>
<p>If you download a small jakarta project, such as Log4J, which is built by ant. It is a good and simple example for you to learn ant. Actually, you hit two birds with one stone.<br />
Ant is easy!<br />
The hard part is how to make a very complicated diversified system work very simple and elegant. Knowledge about ant is not enough, you need an elegant and simple design, you need great naming convention, you need to optimize the code reusability and flexibility, you need a least maintenance system&#8230;<br />
Then it is not easy now ..</p>
<h3>2)How do I get started to use ant? Can you give me a &#8220;Hello World&#8221; ant script?</h3>
<p>Simple.</p>
<ul>
<li>Download the most recent version of ant from Apache; unzip it some where on your machine.</li>
<li>Install j2sdk 1.4 or above.</li>
<li>Set JAVA_HOME and ANT_HOME to the directory your installed them respectively.</li>
<li>Put %JAVA_HOME%/bin;%ANT_HOME%/bin on your Path. Use ${JAVA_HOME}/bin:${ANT_HOME}/bin on UNIX. Yes, you can use forward slash on windows.</li>
<li>Write a &#8220;Hello world&#8221; build.xml</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;project name=&quot;hello&quot; default=&quot;say.hello&quot; basedir=&quot;.&quot; &gt;
                    &lt;property name=&quot;hello.msg&quot; value=&quot;Hello, World!&quot; /&gt;
                    &lt;target name=&quot;say.hello&quot; &gt;
                      &lt;echo&gt;${hello.msg}&lt;/echo&gt;
                    &lt;/target&gt;
                  &lt;/project&gt;</pre></td></tr></table></div>

<p>* Type ant in the directory your build.xml located.</p>
<p>* You are ready to go!!!!</p>
<h3>3)How to delete files from a directory if it exists?</h3>
<p>The following code fails when directory does not exist!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;delete&gt;
    &lt;fileset dir=&quot;${upperdir.which.exists}&quot;&gt;
      &lt;include name=&quot;${classes.dir}/*.class&quot; /&gt;
    &lt;/fileset&gt;
  &lt;/delete&gt;</pre></td></tr></table></div>

<p>Your code has many problems.</p>
<p>1. You should not use implicit fileset, which is deprecated. You should use nested fileset.</p>
<p>2. If dir does not exist, the build will fail, period!</p>
<p>3. If you are not sure, use a upper level dir, which exists for sure. See the following fileset.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;path id=&quot;build.classpath&quot;&gt;
    &lt;fileset dir=&quot;${build.lib}&quot; includes=&quot;**/*.jar&quot;/&gt;
    &lt;fileset dir=&quot;${build.classes}&quot; /&gt;
  &lt;/path&gt;
&nbsp;
  &lt;target....&gt;
    &lt;javac ....&gt;
      &lt;classpath refid=&quot;build.classpath&quot; /&gt;
    &lt;/java&gt;
  &lt;/target&gt;
&nbsp;
  &lt;target....&gt;
    &lt;java ....&gt;
      &lt;classpath refid=&quot;build.classpath&quot; /&gt;
    &lt;/java&gt;
  &lt;/target&gt;</pre></td></tr></table></div>

<h3>5)How does ant read properties? How to set my property system?</h3>
<p>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&#8217;t want to share it with your team members, or not the developers outside your team.</p>
<p>Store your password in your ${user.home}/prj.properties</p>
<p>pswd=yourrealpassword</p>
<p>In your include directory master prj.properties</p>
<p>pswd=password</p>
<p>In your build-common.xml read properties files in this order</p>
<p>1. The commandline will prevail, if you use it: ant<br />
-Dpswd=newpassword</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>2. ${user.home}/prj.properties (personal)</p>
<p>3. yourprojectdir/prj.properties (project team wise)</p>
<p>4. your_master_include_directory/prj.properties (universal)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;cvsnttask password=&quot;${pswd} ... /&gt;</pre></td></tr></table></div>

<p>Problem solved!</p>
<h3>6)How to modify properties in ant?</h3>
<p>No, you can&#8217;t!</p>
<p>Properties in Ant are immutable. There is a good reason behind this, see this FAQ item for more details.</p>
<h3>7)How to use ant-contrib tasks?</h3>
<p>A: Simple, just copy ant-contrib.jar to your ant*/lib directory</p>
<p>And add this line into your ant script, all ant-contrib tasks are now available to you!</p>
<p>&lt;taskdef<br />
resource=&#8221;net/sf/antcontrib/antcontrib.properties&#8221; /&gt;</p>
<h3>8)How to loop on a list or fileset?</h3>
<p>Use ant-contrib &lt;for&gt; &lt;foreach&gt; tasks</p>
<p>General to say, use &lt;for&gt; is better than use &lt;foreach&gt; since for each is actually open another ant property space, use more memory too.</p>
<h3>9)Why do I get en exception when I use location=&#8221;D:\\Code\\include&#8221; as<br />
attribute of includepath?</h3>
<p>See here.</p>
<p>You need to escape the string to &#8220;D:\\\\Code\\\\include&#8221; or use &#8220;D:/Code/include&#8221; instead!</p>
<p>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!</p>
<h3>10)Can I put the contents of a classpath or fileset into a property?</h3>
<p>Yes, you can.</p>
<p>This is very similar to the call of Java class toString() method and actually it is calling the toString() method inside ant. For example</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;fileset id=&quot;fs1&quot; dir=&quot;t1&quot; includes=&quot;**/*.java&quot;/&gt;
&lt;property name=&quot;f1.contents&quot; refid=&quot;fs1&quot;/&gt;
&lt;echo&gt;f1.contents=${f1.contents}&lt;/echo&gt;</pre></td></tr></table></div>

<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'><div class='dd_button_v'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http%3A%2F%2Fwww.javabeat.net%2F2010%2F08%2Fapache-ant-interview-questions%2F" send="false" show_faces="false"  layout="box_count" width="50"  ></fb:like></div><div style='clear:left'></div><div class='dd_button_v'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='tall' href='http://www.javabeat.net/2010/08/apache-ant-interview-questions/'></g:plusone></div><div style='clear:left'></div><div class='dd_button_v'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.javabeat.net/2010/08/apache-ant-interview-questions/" data-count="vertical" data-text="Apache Ant Interview Questions" data-via="javabeat" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style='clear:left'></div><div class='dd_button_extra_v'><script type="text/javascript">jQuery(document).load(function(){ stLight.options({publisher:'bab47279-62c9-46af-addc-79fd1fe8fee0'}); });</script><div class="st_email_custom"><span id='dd_email_text'>email</span></div></div><div style='clear:left'></div><div class='dd_button_extra_v'><div id='dd_print_button'><span id='dd_print_text'><a href='javascript:window:print()'>print</a></span></div></div><div style='clear:left'></div></div></div></div><script type="text/javascript">var dd_offset_from_content = 44; var dd_top_offset_from_content = 0;</script><script type="text/javascript" src="http://www.javabeat.net/wp-content/plugins/digg-digg//js/diggdigg-floating-bar.js?ver=5.3.0"></script><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/08/apache-ant-interview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
