Writing Ant Targets
1) Clean
<target name="clean" description="Clean this project">
<echo message="############################################################" />
<echo message="# Cleaning this project #" />
<echo message="############################################################" />
<delete dir="${proj.webapp.dir}/WEB-INF/classes" failonerror="false" />
<delete dir="${proj.webapp.dir}/${proj.gwt.js.dir}" failonerror="false" />
<delete dir="${proj.webapp.dir}/pages/jasper/out" failonerror="false" />
<delete dir="${proj.dist.dir}" failonerror="false" />
</target>
when executing it does follows,
clean:
[echo] ############################################################
[echo] # Cleaning this project #
[echo] ############################################################
[delete] Deleting directory /home/ishara/Development/Projects/OfficeProjects/Rates3/Rates3Nov28/rates3/war/WEB-INF/classes
It cleans the war/WEB-INF/classes in the src of project chekout folder.
2) javac
<target name="javac" description="Compile java source">
<mkdir dir="${proj.webapp.dir}/WEB-INF/classes" />
<javac srcdir="${proj.java.dir}" destdir="${proj.webapp.dir}/WEB-INF/classes" includes="**"
debug="${proj.compile.debug}" optimize="true" deprecation="false" encoding="utf-8">
<classpath refid="project.class.path" />
</javac>
<copy todir="${proj.webapp.dir}/WEB-INF/classes">
<fileset dir="${proj.java.dir}" />
</copy>
</target>
above does the following.
javac:
[mkdir] Created dir: /home/ishara/Development/Projects/OfficeProjects/Rates3/Rates3Nov28/rates3/war/WEB-INF/classes
[javac] Compiling 460 source files to /home/ishara/Development/Projects/OfficeProjects/Rates3/Rates3Nov28/rates3/war/WEB-INF/classes
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[copy] Copying 519 files to /home/ishara/Development/Projects/OfficeProjects/Rates3/Rates3Nov28/rates3/war/WEB-INF/classes
It creates a directory under /war/WEB-INF/classes of project folder.
Then it compiles /war/WEB-INF/classes and copy those files to /war/WEB-INF/classes newly created folder.
3) war
<target name="war" description="Packaging this project">
<echo message="############################################################" />
<echo message="# Packaging this project #" />
<echo message="############################################################" />
<mkdir dir="${proj.dist.dir}/${proj.webapp.name}" />
<copy todir="${proj.dist.dir}/${proj.webapp.name}">
<fileset dir="${proj.webapp.dir}" excludes="**/*.java" />
</copy>
<!--jar jarfile="${dist.dir}/${webapp.name}.war" index="true">
<fileset dir="${dist.dir}/${webapp.name}" />
</jar-->
</target>
It executees as follows.
war:
[echo] ############################################################
[echo] # Packaging this project #
[echo] ############################################################
[mkdir] Created dir: /home/ishara/Development/Projects/OfficeProjects/Rates3/Rates3Nov28/rates3/dist/irates
[copy] Copying 2525 files to /home/ishara/Development/Projects/OfficeProjects/Rates3/Rates3Nov28/rates3/dist/irates
[copy] Copied 298 empty directories to 2 empty directories under /home/ishara/Development/Projects/OfficeProjects/Rates3/Rates3Nov28/rates3/dist/irates
It creates a direcotry under rates3 src fodler as /dist/irates.
Then copy fiels to that folder, and copy the folders as well.
4) deploy
<target name="deploy-web-node1" description="Deploys on Web Node 1">
<macro-deploy name="web node 1" node="${proj.server.web.node1}"/> </target>
It executes as follows.
deploy-web-node1:
[echo] ##############################################################
[echo] # Deploys on web node 1 #
[echo] ##############################################################
[delete] Deleting directory /home/ishara/Development/Tomcat/apache-tomcat-6.0.35/conf/Catalina
[copy] Copying 2525 files to /home/ishara/Development/Tomcat/apache-tomcat-6.0.35/webapps/irates
[copy] Copied 299 empty directories to 2 empty directories under /home/ishara/Development/Tomcat/apache-tomcat-6.0.35/webapps/irates
It deletes the/ apache-tomcat-6.0.35/conf/Catalina directory.
Then copy files to /apache-tomcat-6.0.35/webapps/irates and copy the folder to that directory as well.
Below is the complete ant build file used for Rates project and a full deploy following will have to be executed.
ant clean compile war deploy-web-node1
but if we do not have client side changes, then without using gwtc below is enough.
ant clean javac apply-env war deploy-web-node1
Build file is as below.
<?xml version="1.0" encoding="utf-8" ?>
<project name="Rates" default="compile" basedir=".">
<import file="properties.xml" />
<path id="project.class.path">
<pathelement location="${proj.webapp.dir}/WEB-INF/classes" />
<fileset dir="${proj.ext-lib.dir}" includes="*.jar" />
<fileset dir="${proj.webapp.dir}/WEB-INF/lib" includes="*.jar" />
</path>
<target name="clean" description="Clean this project">
<echo message="############################################################" />
<echo message="# Cleaning this project #" />
<echo message="############################################################" />
<delete dir="${proj.webapp.dir}/WEB-INF/classes" failonerror="false" />
<delete dir="${proj.webapp.dir}/${proj.gwt.js.dir}" failonerror="false" />
<delete dir="${proj.webapp.dir}/pages/jasper/out" failonerror="false" />
<delete dir="${proj.dist.dir}" failonerror="false" />
</target>
<target name="javac" description="Compile java source">
<mkdir dir="${proj.webapp.dir}/WEB-INF/classes" />
<javac srcdir="${proj.java.dir}" destdir="${proj.webapp.dir}/WEB-INF/classes" includes="**"
debug="${proj.compile.debug}" optimize="true" deprecation="false" encoding="utf-8">
<classpath refid="project.class.path" />
</javac>
<copy todir="${proj.webapp.dir}/WEB-INF/classes">
<fileset dir="${proj.java.dir}" />
</copy>
</target>
<target name="apply-env" description="Apply env properties into build process" if="proj.env">
<echo message="############################################################" />
<echo message="# Applying ENV ${proj.env} propertis #" />
<echo message="############################################################" />
<copy file="${proj.res.dir}/env/${proj.env}/system.properties"
tofile="${proj.webapp.dir}/WEB-INF/classes/system.properties"
overwrite="true" failonerror="true" />
<copy file="${proj.res.dir}/env/${proj.env}/context.xml"
tofile="${proj.webapp.dir}/META-INF/context.xml"
overwrite="true" failonerror="true" />
<copy file="${proj.res.dir}/env/${proj.env}/Rates.gwt.xml"
tofile="${proj.webapp.dir}/WEB-INF/classes/shipxpress/rates3/Rates.gwt.xml"
overwrite="true" failonerror="true" />
</target>
<target name="gwtc" description="GWT compile to JavaScript">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler">
<classpath>
<path refid="project.class.path" />
</classpath>
<jvmarg value="${proj.runtime.initmemory}" />
<jvmarg value="${proj.runtime.maxmemory}" />
<jvmarg value="${proj.runtime.permgensize}" />
<arg value="${proj.gwt.module}" />
</java>
</target>
<target name="jasperc" description="Jasper compile">
<echo message="#################Compiling the Jasper Report from jrxml#################" />
<mkdir dir="${proj.webapp.dir}/pages/jasper/out" />
<taskdef name="jrc" classname="net.sf.jasperreports.ant.JRAntCompileTask">
<classpath>
<fileset dir="${proj.ext-lib.dir}" includes="*.jar" />
<fileset dir="${proj.webapp.dir}/WEB-INF/lib" includes="*.jar" />
</classpath>
</taskdef>
<jrc srcdir="${proj.webapp.dir}/pages/jasper" destdir="${proj.webapp.dir}/pages/jasper/out" includes="*.jrxml" />
</target>
<target name="compile" depends="javac,apply-env,gwtc,jasperc" description="Compiling this project">
<echo message="############################################################" />
<echo message="# Compiling this project #" />
<echo message="############################################################" />
</target>
<target name="war" description="Packaging this project">
<echo message="############################################################" />
<echo message="# Packaging this project #" />
<echo message="############################################################" />
<mkdir dir="${proj.dist.dir}/${proj.webapp.name}" />
<copy todir="${proj.dist.dir}/${proj.webapp.name}">
<fileset dir="${proj.webapp.dir}" excludes="**/*.java" />
</copy>
<!--jar jarfile="${dist.dir}/${webapp.name}.war" index="true">
<fileset dir="${dist.dir}/${webapp.name}" />
</jar-->
</target>
<target name="gwt-debug-mode" description="Run GWT debug mode">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.DevMode">
<classpath>
<fileset dir="${proj.gwt.debug.sdk}" includes="*.jar" />
<path refid="project.class.path" />
</classpath>
<jvmarg value="${proj.runtime.initmemory}" />
<jvmarg value="${proj.runtime.maxmemory}" />
<jvmarg value="${proj.runtime.permgensize}" />
<jvmarg value="-Xdebug" />
<jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${proj.gwt.debug.client.debug.port}" />
<arg value="-noserver" />
<arg value="-port" />
<arg value="${proj.gwt.debug.server.http.port}" />
<arg value="-startupUrl" />
<arg value="/${proj.webapp.name}" />
<arg value="${proj.gwt.module}" />
</java>
</target>
<macrodef name="macro-deploy">
<attribute name="node" default="${proj.server.web.node1}"/>
<attribute name="name" default=""/>
<sequential>
<echo message="##############################################################"/>
<echo message="# Deploys on @{name} #"/>
<echo message="##############################################################"/>
<delete includeemptydirs="true" casesensitive="false">
<fileset dir="@{node}/work" includes="**/*"/>
</delete>
<delete includeemptydirs="true" casesensitive="false">
<fileset dir="@{node}/temp" includes="**/*"/>
</delete>
<delete dir="@{node}/conf/Catalina"/>
<delete dir="@{node}/webapps/${proj.webapp.name}"/>
<copy todir="@{node}/webapps/${proj.webapp.name}" overwrite="true">
<fileset dir="${proj.dist.dir}/${proj.webapp.name}"/>
</copy>
</sequential>
</macrodef>
<target name="deploy-web-node1" description="Deploys on Web Node 1">
<macro-deploy name="web node 1" node="${proj.server.web.node1}"/>
</target>
<target name="deploy-web-node2" description="Deploys on Web Node 2">
<macro-deploy name="web node 2" node="${proj.server.web.node2}"/>
</target>
<target name="deploy-job-node" description="Deploys on Job Node">
<macro-deploy name="web node 1" node="${proj.server.job.node}"/>
</target>
<target name="checkstyle" description="Static code analysing is performed" >
<taskdef resource="checkstyletask.properties" classpath="${checkstyle.home}/checkstyle-5.3-all.jar"/>
<checkstyle config="${proj.res.dir}/checkstyle/shipx_check_style.xml" failOnViolation="false">
<fileset dir="${proj.java.dir}/" includes="**/*.java"/>
<formatter type="plain"/>
<formatter type="xml" tofile="reports/checkstyle-report.xml"/>
</checkstyle>
<xslt in="reports/checkstyle-report.xml" style="${checkstyle.home}/contrib/checkstyle-noframes.xsl"
out="reports/checkstyle-report.html"/>
</target>
<target name="all" depends="checkstyle, compile, war, deploy-web-node1" description="All taks">
<echo message="############################################################" />
<echo message="# Building the Project #" />
<echo message="############################################################" />
</target>
<target name="all-with-clean" depends="clean, all" description="All taks with clean">
<echo message="############################################################" />
<echo message="# Cleaning and Building the Project #" />
<echo message="############################################################" />
</target>
</project>