Introduction to Ant www.scmGalaxy.com scmGalaxy Author: Rajesh Kumar [email_address]
<ul><li>What is ANT? </li></ul><ul><li>Installation </li></ul><ul><li>Sample build.xml </li></ul><ul><li>Executing ant scr...
What is ANT? <ul><li>A nother  N eat  T ool </li></ul><ul><li>Java-based build tool  </li></ul><ul><li>Like  make , withou...
Installation <ul><li>Download the binaries from  http://jakarta.apache.org/ant/index.html </li></ul><ul><li>Unzip to a sui...
Working with ANT <ul><li>Every project using ANT will have a build file –  build.xml </li></ul><?xml version=&quot;1.0&quo...
A simple build.xml <ul><li><?xml version=&quot;1.0&quot;?>  </li></ul>XML declaration specifying version of XML used.  All...
A simple build.xml  [Contd.] < property  name=&quot;src&quot; value=&quot;.&quot;/>  <property name=&quot;build&quot; valu...
A simple build.xml  [Contd.] <target name=&quot;init&quot;> <mkdir dir=&quot;${build}&quot;/> </target> <ul><li>target ele...
A simple build.xml  [Contd.] < target  name=&quot;compile&quot; depends=&quot;init&quot;>  <javac srcdir=&quot;${src}&quot...
Executing ant script ant [options] [target [target2 [target3] ...]]  Options:  -help    print this message  -projecthelp  ...
Path-like structures -  classpath <ul><li>Wherever path-like values need to be specified, a nested element can be used :  ...
Path-like structures -  path <ul><li>To use the same path-like structure for several tasks, you can define them with a <pa...
Path-like structures –   dirset, fileset,filelist <classpath> <pathelement path=&quot;${classpath}&quot;/> < fileset  dir=...
Tasks <ul><li>Piece of code that can be executed </li></ul><ul><li>Built-in tasks : </li></ul><ul><ul><li>javac, java, jav...
javac <ul><li>Compiles a java source tree </li></ul><ul><li>Source & destination directory recursively scanned for .java f...
Building subprojects  - ant <ul><li>Runs Ant on supplied build file </li></ul><ul><li>This task must not be used outside o...
Calling other targets  - antcall <ul><li>Call another target within the same build-file (optionally specifying properties)...
Advantages <ul><li>Ease of use </li></ul><ul><ul><li>Configuration files are XML based </li></ul></ul><ul><ul><li>Same con...
Advantages  [Contd.] <ul><li>Particularly good for automating complicated repetitive tasks which is what most build proces...
PACKAGING
<ul><li>ejb-jar file will contain : </li></ul><ul><ul><li>Beans’ class files </li></ul></ul><ul><ul><li>Beans’ deployment ...
<ul><li>Has specific hierarchical directory structure </li></ul><ul><li>Top-level directory is the document root of applic...
<ul><li>An EAR file can contain : </li></ul><ul><ul><li>Web components (war) </li></ul></ul><ul><ul><li>Beans (ejb-jar) </...
References <ul><li>Ant home page </li></ul><ul><li>http://ant.apache.org/ </li></ul><ul><li>Ant manual </li></ul><ul><li>h...
www.scmGalaxy.com Thank You ! Author: Rajesh Kumar [email_address]
Upcoming SlideShare
Loading in …5
×

Introduction To Ant

3,087 views

Published on

Ant is a Java library and command-line tool. Ant's mission is to drive processes 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.

Ant is written in Java. Users of Ant can develop their own "antlibs" containing Ant tasks and types, and are offered a large number of ready-made commercial or open-source "antlibs".

Ant is extremely flexible and does not impose coding conventions or directory layouts to the Java projects which adopt it as a build tool.

Software development projects looking for a solution combining build tool and dependency management can use Ant in combination with Ivy.

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,087
On SlideShare
0
From Embeds
0
Number of Embeds
240
Actions
Shares
0
Downloads
118
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Introduction To Ant

    1. 1. Introduction to Ant www.scmGalaxy.com scmGalaxy Author: Rajesh Kumar [email_address]
    2. 2. <ul><li>What is ANT? </li></ul><ul><li>Installation </li></ul><ul><li>Sample build.xml </li></ul><ul><li>Executing ant script </li></ul><ul><li>Closer look at the structure of ANT file </li></ul><ul><li>Advantages of using ANT </li></ul><ul><li>Packaging – JAR, WAR, EAR </li></ul>Agenda
    3. 3. What is ANT? <ul><li>A nother N eat T ool </li></ul><ul><li>Java-based build tool </li></ul><ul><li>Like make , without make ’s wrinkles  </li></ul><ul><li>An open source Apache Jakarta project </li></ul><ul><ul><li>http://ant.apache.org/ </li></ul></ul><ul><li>Implemented in Java, implemented for Java </li></ul>
    4. 4. Installation <ul><li>Download the binaries from http://jakarta.apache.org/ant/index.html </li></ul><ul><li>Unzip to a suitable directory </li></ul><ul><li>Set ANT_HOME = path_to_ant_folder </li></ul><ul><li>Append PATH=%PATH%;%ANT_HOME%in to the PATH environment variable </li></ul><ul><li>Append the .jar files in /path_to_ant/lib/ to the CLASSPATH environment variable </li></ul><ul><li>Ensure that JAVA_HOME points to the location of the JDK installation on your machine & /path_to_jdk/lib/* is a part of the CLASSPATH environment variable </li></ul>
    5. 5. Working with ANT <ul><li>Every project using ANT will have a build file – build.xml </li></ul><?xml version=&quot;1.0&quot;?> <project name=&quot;test&quot; default=&quot;compile&quot; basedir=&quot;.&quot;> <property name=&quot;src&quot; value=&quot;.&quot;/> <property name=&quot;build&quot; value=&quot;build&quot;/> <target name=&quot;init&quot;> <mkdir dir=&quot;${build}&quot;/> </target> <target name=&quot;compile&quot; depends=&quot;init&quot;> <!-- Compile the java code --> <javac srcdir=&quot;${src}&quot; destdir=&quot;${build}&quot;/> </target> </project>
    6. 6. A simple build.xml <ul><li><?xml version=&quot;1.0&quot;?> </li></ul>XML declaration specifying version of XML used. All XML constraints hold good for build.xml < project name=“test&quot; default=&quot;compile&quot; basedir=&quot;.&quot;> <ul><li>project – root element of build.xml </li></ul><ul><li>It has 3 attributes </li></ul><ul><ul><li>name – name of project </li></ul></ul><ul><ul><li>default – (mandatory) default target when no target is specified </li></ul></ul><ul><ul><li>basedir – directory from which any relative directories within build.xml are referenced from </li></ul></ul>
    7. 7. A simple build.xml [Contd.] < property name=&quot;src&quot; value=&quot;.&quot;/> <property name=&quot;build&quot; value=&quot;build&quot;/> <ul><li>Property declaration is like user-defined variables to use within the build file </li></ul><ul><li>It has 2 attributes </li></ul><ul><ul><li>name – name of property </li></ul></ul><ul><ul><li>value – desired value of the property </li></ul></ul><ul><li>To reference a property, ${property_name} - ${src} </li></ul><ul><li>Built in properties that ANT provides : </li></ul><ul><ul><li>basedir   ant.file </li></ul></ul><ul><ul><li>ant.version  ant.project.name </li></ul></ul><ul><ul><li>ant.java.version </li></ul></ul>
    8. 8. A simple build.xml [Contd.] <target name=&quot;init&quot;> <mkdir dir=&quot;${build}&quot;/> </target> <ul><li>target element is a wrapper for a sequence of actions </li></ul><ul><li>Has the following attributes </li></ul><ul><ul><li>name – (mandatory) Name used to reference this target from within the file or from command line </li></ul></ul><ul><ul><li>description – short description of this target </li></ul></ul><ul><ul><li>if – to conditionally execute contents of target based on the value of a property </li></ul></ul><ul><ul><li>unless – converse of if </li></ul></ul>
    9. 9. A simple build.xml [Contd.] < target name=&quot;compile&quot; depends=&quot;init&quot;> <javac srcdir=&quot;${src}&quot; destdir=&quot;${build}&quot;/> </target> <ul><ul><li>depends – comma separated list of all the targets on which this target depends, i.e, targets that must be executed prior to the execution of this target </li></ul></ul><ul><li>javac element is a task which is performed under the target compile </li></ul><ul><li>By default, only those .java input files that have a more recent timestamp than their corresponding .class output files will be compiled </li></ul>
    10. 10. Executing ant script ant [options] [target [target2 [target3] ...]] Options: -help print this message -projecthelp print project help information -version print the version information and exit -diagnostics print information that might be helpful to diagnose or report problems. -quiet, -q be extra quiet -verbose, -v be extra verbose -debug print debugging information -emacs produce logging information without adornments -logfile <file> use given file for log -l <file> '' -logger <classname> the class which is to perform logging -listener <classname> add an instance of class as a project listener -buildfile <file> use given buildfile -file <file> '' -f <file> '' -D<property>=<value> use value for given property -propertyfile taking precedence -inputhandler <class> the class which will handle input requests -find <file> <name> load all properties from file with -D properties search for buildfile towards the root of the file system and use it
    11. 11. Path-like structures - classpath <ul><li>Wherever path-like values need to be specified, a nested element can be used : </li></ul><ul><ul><li>location - specifies a single file or directory relative to the project's base directory or an absolute filename </li></ul></ul><ul><ul><li>path - accepts “ : ” or “ ; ” separated lists of locations </li></ul></ul>< classpath > <pathelement path=&quot;${classpath}&quot;/> <pathelement location=&quot;lib/helper.jar&quot;/> </classpath> <classpath path =“${classpath}”/>
    12. 12. Path-like structures - path <ul><li>To use the same path-like structure for several tasks, you can define them with a <path> element at the same level as targets, and reference them via their id attribute </li></ul>< path id=&quot;project.class.path&quot;> <path refid=&quot;base.path&quot;/> <pathelement location=&quot;lib/&quot;/> </path> <classpath refid=&quot;project.class.path&quot;/>
    13. 13. Path-like structures – dirset, fileset,filelist <classpath> <pathelement path=&quot;${classpath}&quot;/> < fileset dir=&quot;lib&quot;> <include name=&quot;**/*.jar&quot;/> </fileset> <pathelement location=&quot;classes&quot;/> < dirset dir=&quot;${build.dir}&quot;> <include name=&quot;apps/**/classes&quot;/> <exclude name=&quot;apps/**/*Test*&quot;/> </dirset> < filelist dir=&quot;${src.dir}&quot; files=&quot;foo.xml,bar.xml&quot;/> </classpath>
    14. 14. Tasks <ul><li>Piece of code that can be executed </li></ul><ul><li>Built-in tasks : </li></ul><ul><ul><li>javac, java, javadoc, javah, junit </li></ul></ul><ul><ul><li>mkdir, copy, move, delete, fileset </li></ul></ul><ul><ul><li>jar, war, zip, unjar, unwar, unzip </li></ul></ul><ul><ul><li>echo, cvs, exec </li></ul></ul><ul><ul><li>ant, antcall </li></ul></ul><ul><li>You can also write your own tasks </li></ul>
    15. 15. javac <ul><li>Compiles a java source tree </li></ul><ul><li>Source & destination directory recursively scanned for .java files to compile </li></ul><ul><li>By default only check made for rebuild is existence / modification time </li></ul><ul><li>To define any other java class dependencies use task <depend> </li></ul>< javac debug=&quot;${debug}&quot; optimize=&quot;${optimize}&quot; deprecation=&quot;${deprecation}&quot; destdir=&quot;${build.dest}&quot; includes=&quot;com/**&quot; excludes=&quot;**/*.xml&quot;> <src path=&quot;${src.dir}&quot; />   <classpath refid=&quot;classpath&quot; />   </javac> There are many more attributes / options available. Check Ant User Manual for more info.
    16. 16. Building subprojects - ant <ul><li>Runs Ant on supplied build file </li></ul><ul><li>This task must not be used outside of a target if it invokes the same build file that it is part of </li></ul>< ant antfile=&quot;subproject/subbuild.xml&quot; dir=&quot;subproject&quot; target=&quot;compile&quot;/> < ant inheritAll=&quot;false&quot; antfile=&quot;subproject/subbuild.xml&quot;> <property name=&quot;output.type&quot; value=&quot;html&quot;/> </ant>
    17. 17. Calling other targets - antcall <ul><li>Call another target within the same build-file (optionally specifying properties) </li></ul><ul><li>This task must no be used outside of a target </li></ul><target name=&quot;default&quot;> < antcall target=&quot;doSomethingElse&quot;> <param name=&quot;param1&quot; value=&quot;value&quot;/> </antcall> </target> <target name=&quot;doSomethingElse&quot;> <echo message=&quot;param1=${param1}&quot;/> </target>
    18. 18. Advantages <ul><li>Ease of use </li></ul><ul><ul><li>Configuration files are XML based </li></ul></ul><ul><ul><li>Same config file (build.xml) can be used across platforms </li></ul></ul><ul><li>Platform independent </li></ul><ul><li>Special support for Java </li></ul><ul><ul><li>Easy to create JavaDocs, WAR & JAR files </li></ul></ul><ul><li>Built-in support for </li></ul><ul><ul><li>JUnit </li></ul></ul><ul><ul><li>FTP </li></ul></ul><ul><ul><li>CVS </li></ul></ul>
    19. 19. Advantages [Contd.] <ul><li>Particularly good for automating complicated repetitive tasks which is what most build processes are all about! </li></ul><ul><li>ANT can be integrated with most Java IDEs </li></ul><ul><ul><li>Eclipse </li></ul></ul><ul><ul><li>Jbuilder </li></ul></ul><ul><ul><li>IntelliJIdea </li></ul></ul>
    20. 20. PACKAGING
    21. 21. <ul><li>ejb-jar file will contain : </li></ul><ul><ul><li>Beans’ class files </li></ul></ul><ul><ul><li>Beans’ deployment descriptors </li></ul></ul><ul><ul><ul><li>META-INF/ejb-jar.xml </li></ul></ul></ul><ul><ul><ul><li>Application server specific file (e.g. META-INF/jboss.xml) </li></ul></ul></ul><ul><li>Sample ejb-jar.xml </li></ul><ul><li>Sample application specific descriptor file </li></ul>EJB Packaging – ejb-jar
    22. 22. <ul><li>Has specific hierarchical directory structure </li></ul><ul><li>Top-level directory is the document root of application </li></ul><ul><li>WAR has the following folders (usually): </li></ul><ul><ul><li>jsp – JSP files </li></ul></ul><ul><ul><li>images – images used in the JSPs </li></ul></ul><ul><ul><li>css – style sheet files </li></ul></ul><ul><ul><li>scripts – javascript files </li></ul></ul><ul><ul><li>WEB-INF </li></ul></ul><ul><li>WEB-INF folder contains </li></ul><ul><ul><li>Configuration files like web.xml, struts-config.xml </li></ul></ul><ul><ul><li>.tld files (if any) </li></ul></ul><ul><ul><li>lib : directory that contains jar archives of libraries </li></ul></ul><ul><ul><li>classes : directory that contains the servlet classes and utility classes </li></ul></ul>Web ARchive (WAR)
    23. 23. <ul><li>An EAR file can contain : </li></ul><ul><ul><li>Web components (war) </li></ul></ul><ul><ul><li>Beans (ejb-jar) </li></ul></ul><ul><ul><li>Libraries (jar) </li></ul></ul><ul><ul><li>J2EE deployment descriptor (META-INF/application.xml) </li></ul></ul><ul><li>Sample application.xml </li></ul>Enterprise ARchive (EAR)
    24. 24. References <ul><li>Ant home page </li></ul><ul><li>http://ant.apache.org/ </li></ul><ul><li>Ant manual </li></ul><ul><li>http://ant.apache.org/manual/index.html </li></ul><ul><li>Another beginner’s tutorial http://supportweb.cs.bham.ac.uk/documentation/tutorials/docsystem/build/tutorials/ant/ant.html </li></ul>
    25. 25. www.scmGalaxy.com Thank You ! Author: Rajesh Kumar [email_address]

    ×