JavaBeat FAQs
JAVABEAT
Home
Articles
Tips
QnA
Forums
FAQs Topics Books Topic
Java Java Books
Struts Struts Books
Spring Spring Books
Hibernate Hibernate Books
JBoss Seam Seam Books
J2EE J2EE Books
EJB EJB Books
JSF JSF Books
Servlets Servlets Books
JDBC JDBC Books
RMI RMI Books
JMS JMS Books
JNI JNI Books
Design Patterns Patterns Books
Exception Exception Books
Apache Ant Ant Books
Groovy
Cobertura
Quartz

Apache Ant Interview Questions

Apache Ant FAQs - 1 | Apache Ant FAQs - 2 | Apache Ant FAQs - 3

Apache Ant Interview Questions - 2

1)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.

2)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>

3)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.

4)How do I debug my ant script?

Many ways

    * 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()
    * Use project.log("msg") in your javascript or custom ant task
    * 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.


5)How to exclude multi directories in copy or delete task?

Here is an example.
    
  <copy todir="${to.dir}" >
    <fileset dir="${from.dir}" >
      <exclude name="dirname1" />
      <exclude name="dirname2" />
      <exclude name="abc/whatever/dirname3" />
      <exclude name="**/dirname4" />
    </fileset>
  </copy>

6)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");

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

No, you don't 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.

See the follow example:

  <jar destfile="${dest}/my.jar">
    <zipfileset src="old_archive.zip" includes="**/*.properties" prefix="dir_in_new_archive/prop"/>
    <zipfileset dir="curr_dir/abc" prefix="new_dir_in_archive/xyz"/>
  </jar>
  

8)Why did I get such warning in ant?

compile:
[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.


9)How can I write my own ant task?

Easy!
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.

10)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="**/*.*"/>


Bookmark This Page : | | | | | | | | | | |
Related Articles
Liferay Portal Enterprise Intranets
ZK Developer’s Guide : Online Media Library
The BIRT Environment and Your First Report
AJAX - The Complete Reference
The Java 6.0 Compiler API
Spring Web Flow - Introduction
Introduction to Spring Web Framework
Integrating Struts With Spring
What's new in Struts 2.0? - Struts 2.0 Framework
Introductiion to Jakarta Struts
more articles
java6 ejb3 jsf hibernate eclipse ajax groovy spring seam java struts webservice j2me guice java5 jca tapestry soa linux ria

Sponsors
Webmaster Hosting Forum
Java Jobs
Latest in DLinks
http://javawave.blogspot.com/2008/04/quartz-job-scheduler-part-ii-example.html
Quartz Job Scheduler -- Part 1 (Setting up development project in Netbeans 6.1 beta)
Flex Messaging with BEA Workshop Studio
SOA and Virtualization: How do They Fit Together?
Introduction to Enterprise Portals - Why they Benefit IT and the Business
BEA WebLogic Operations Control: Application Virtualization for Enterprise Java
Best Practices for Building Production Quality EAR Files
BEA's SOA Reference Architecture - A Foundation for Business Agility
Blueprint for Successful SOA Integration
Guardian - What a tool!

JavaBeat Media (2004-2008), India
javabeat home | About Us
our network : opensource softwares
Copyright © 2007 JavaBeat