Professional Documents
Culture Documents
Pralhad Vernekar
Introduction
• Ant : Primarily a Build tool
• Junit :Used for testing
Project
props
Paths
Target Compile
Uses javac, classpath taken from paths
• clean:
• [echo] cleaning folder
• [delete] Deleting 1 files from C:\training\ant\example1
• compile:
• [javac] Compiling 1 source file
• BUILD SUCCESSFUL
• Total time: 1 second
Ant Exercise – One
• Write a build.xml
- clean compilation
- Create a jar, with .class and properties files
- Copy .jar to dest
- Run the java program using .jar in the classpath
Few More Tasks
• Java
• Javac
• Jar
• Copy
• Condition
• In detail
Exercise - Two
• Go through Ant Core tasks and write a simple
build file to demo an Ant Task not related to
JAVA
• Java, javac, javadoc, jar
Typical Project
• Properties - property
• Paths - path
• Init - delete
• Compile (javac)
• Packaging (jar)
• Deployment – copy, copy jsps etc
• Testing - junit
Advanced Concepts
• Filesets
• <fileset dir="${server.src}" casesensitive="yes">
– <filename name="**/*.java"/>
– <not>
– <filename name="**/*Test*"/> </not>
• </fileset>
Advanced Concepts
• FileList, Id
• <filelist
– id="docfiles"
– dir="${doc.src}"
– files="foo.xml,bar.xml"/>
Advanced Concepts
• Permissions
• <permissions>
– <grant class="java.net.SocketPermission" name="foo.bar.com"
action="connect"/>
– <grant class="java.util.PropertyPermission" name="user.home"
action="read,write"/>
• </permissions>
Advanced Concepts
• Conditions
• <condition property="javamail.complete">
– <and>
– <available classname="javax.activation.DataHandler"/>
– <available classname="javax.mail.Transport"/>
– </and>
• </condition>
• <target name=“compile” if=“javamail.complete”>
– …
• </target>
Type of Tasks
• Property
• Compile
• Archive
• Documentation
• Deployment
• Logging, Mailing
• Testing
Exercise - 3
• Compare Contents of same file in different
directories
– First
– Second
Optional Tasks
• Typically tasks which are provided by other
vendors/freeware writer.
• Junit
• JspC
• ftp, telnet
• Clearcase, pvcs
• rpm
Extending Task
• Org.apache.tools.ant.Task
• Tutorial : Writing task
• C:\pvinstalled\apache-ant-
1.6.0\docs\manual\tutorial-writing-tasks.html
Extending Task
• Write execute function
• Setting Attributes
• Nested Elements
Exercise : later
• Write a task
• Input fromdir, todir
• Compares contents of two directories
• Optimize as much as possible.
Build.xml + local.props
Exercise
1. com.pspl.batch1.PersonBean.java
2. showperson.jsp
create instance of personbean and show details
3. webappname : personsinfo
4. build.xml
1. compile .java files
2. copy *.jsp to the right webapp – webapp exists (create a directory in tomcat
before running ant)