Required Software -
Ant 1.8.2
Java 1.6
Tomcate 6.0.26
Extract Ant 1.8.2.zip as
Extract apache-tomcat-6.0.26.zip as C:/apache-tomcat-6.0.26
CATALINA_HOME = C:/apache-tomcat-6.0.26
ANT_HOME =
C:/Ant/Ant Build Demo/apache-ant-1.8.2;
PATH =C:/jdk1.6./bin;C:/Ant/Ant Build Demo/apache-ant-1.8.2/bin;
PATH =C:/jdk1.6./bin;C:/Ant/Ant Build Demo/apache-ant-1.8.2/bin;
SET JVM_ARGS="-Xms1024m -Xmx1024m"
CLASSPATH=C:/Ant/Ant Build Demo/apache-ant-1.8.2/jar/catalina-ant-5.5.23.jar;C:/Ant/Ant Build Demo/apache-ant-1.8.2/jar/commons-net-1.4.1.jar;
1. Following structure for the creating a build.xml
<?xml version="1.0" ?>
<project name="TESTWebApp" default="war" basedir=".">
--------------------
--------------------
</project>
2. Assigned variable from property file
<?xml version="1.0" ?>
<project name="TESTWebApp" default="war" basedir=".">
<property file="build.properties" />
<property name="project-name" value="${project.name}" />
<property name="builder" value="${project.builder}" />
<tstamp prefix="build-info">
<format property="current-date" pattern="dd-MM-yyyy" locale="en" />
<format property="current-time" pattern="hh:mm:ss a z" locale="en" />
</tstamp>
<property name='app.version' value='${app.version}'/>
<property name='app.name' value='${app.name}'/>
<property name='ant.config.xml.home' value='${ant.config.xml.home}'/>
</project>
3. Auto Increment Version for the War/Jar/Ear file.
<?xml version="1.0" ?>
<project name="TESTWebApp" default="war" basedir=".">
<property file="version.properties" />
<property name='app.build.version' value='${app.build.version}'/>
<property name='app.major' value='${app.major}'/>
<property name='app.minor' value='${app.minor}'/>
<target name="version" >
<propertyfile file="version.properties">
<entry key="app.build.version" type="int" default="0" operation="+" />
</propertyfile>
</target>
</project>
4. Replace a phrase from file with values from property file.
In following Exmple :
"@build-timestamp@" replace with generated current time stamp using ant.
"@build-
version@" replace with auto incremented build version number.
<?xml version="1.0" ?>
<project name="TESTWebApp" default="replace" basedir=".">
<target name="replace" depends="version">
<replace file="${web.dir}/index.jsp" token="@build-timestamp@" value="${build- info.current-date}:${build-info.current-time}" />
<replace file="${web.dir}/index.jsp" token="@build-version@" value="${project.name}- ${app.build.version}.${app.major}.${app.minor}" />
</target>
</project>
5. Configure the class-path for compiling all the Java file with all the required .jar
In following Example :
"web.lib.dir" - adding all the available jar in class-path
6. Compile all the Java source code from the respective SRC folder.
In following Example :
<javac destdir="${build.classes.dir}"
debug="true"
srcdir="${build.src.dir}">
<classpath refid="compile.classpath" />
</javac>
<echo>complile all java file and place into respective folder</echo>
</target>
</project>
7. Copy all the file from SRC of specified pattern to DEST.
In following Example :
8. Execute target jar for creating jar file from compiled classes
In following Example :
9. Execute target war , for creating war file from jar file
In following Example :
<target name="war" depends="jar">
<war destfile="${dist.dir}/${dist.dir.war}/${project.name}-
${app.build.version}.${app.major}.${app.minor}.war"
webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}" >
<exclude name="WEB-INF/web.xml" />
</fileset>
<lib dir="${dist.dir}/${dist.dir.jar}" />
</war>
<echo>war generated :: ${project.name}-${app.build.version}.${app.major}.${app.minor}.war
</echo>
</target>
</project>
9. Execute target war , for creating war file from compiled classes file
In following Example :
"build.classes.dir" - folder under all compile clasess placed.
10. build.proprties
#################################################################################
####### Output Folder Tree Stucture ##############
#################################################################################
dist.dir=c:/Ant/Ant Build Demo/dist
dist.dir.war=war
dist.dir.jar=jar
#################################################################################
####### Project Specific Details ##############
#################################################################################
web.dir=C:/apache-tomcat-6.0.26/webapps/TESTWebApp
web.lib.dir=${web.dir}/WEB-INF/lib
build.classes.dir=${web.dir}/WEB-INF/classes
build.src.dir = ${web.dir}/WEB-INF/src
project.name=TESTWebApp
tomcat.dir=C:/apache-tomcat-6.0.26/
tomcat.web.lib.dir=${tomcat.dir}/lib
project.builder = Shrikant
app.version =1.0
app.name = TESTWebApp
ant.config.xml.home=C:/Ant/Ant Build Demo/apache-ant-1.8.2
10. version.proprties
#################################################################################
####### Version History ##############
#################################################################################
app.build.version=13
<target name="replace" depends="version">
<replace file="${web.dir}/index.jsp" token="@build-timestamp@" value="${build- info.current-date}:${build-info.current-time}" />
<replace file="${web.dir}/index.jsp" token="@build-version@" value="${project.name}- ${app.build.version}.${app.major}.${app.minor}" />
</target>
</project>
5. Configure the class-path for compiling all the Java file with all the required .jar
In following Example :
"web.lib.dir" - adding all the available jar in class-path
"tomcat.web.lib.dir" - adding all the available jar in class-path
"ant.config.xml.home}/jar" - adding all the available jar in class-path
<?xml version="1.0" ?>
<project name="TESTWebApp" default="war" basedir=".">
<path id="compile.classpath">
<fileset dir="${web.lib.dir}">
<include name="*.jar" />
</fileset>
<fileset dir="${tomcat.web.lib.dir}">
<include name="*.jar" />
</fileset>
<fileset dir="${ant.config.xml.home}/jar">
<include name="*.jar" />
</fileset>
</path>
</project>
<path id="compile.classpath">
<fileset dir="${web.lib.dir}">
<include name="*.jar" />
</fileset>
<fileset dir="${tomcat.web.lib.dir}">
<include name="*.jar" />
</fileset>
<fileset dir="${ant.config.xml.home}/jar">
<include name="*.jar" />
</fileset>
</path>
</project>
6. Compile all the Java source code from the respective SRC folder.
In following Example :
"build.classes.dir" - destdir, use as destination folder to store all compile files.
"build.src.dir" - srcdir , use as source folder to compile all the java files.
"compile.classpath" - classpath , use for all the compilation.
"debug=true" - use to set the log level
"depends=clean" - clean is a target which is execute before compile (Optional).
echo tag basically use for the information message.
<?xml version="1.0" ?>
<project name="TESTWebApp" default="compile" basedir=".">
<target name="compile" depends="clean">
<mkdir dir="${build.classes.dir}" /><target name="compile" depends="clean">
<javac destdir="${build.classes.dir}"
debug="true"
srcdir="${build.src.dir}">
<classpath refid="compile.classpath" />
</javac>
<echo>complile all java file and place into respective folder</echo>
</target>
</project>
7. Copy all the file from SRC of specified pattern to DEST.
In following Example :
"build.classes.dir" - destdir, use as destination folder to store all compile files.
"build.src.dir" - srcdir , use as source folder to compile all the java files.
"meta.files" - use for all the for defined pattern.
"depends=compile" - compile is a target which is execute before copy.meta.files
(Optional).
(Optional).
<?xml version="1.0" ?>
<project name="TESTWebApp" default="
copy.meta.files" basedir=".">
<patternset id="meta.files">
<include name="**/*.xml" />
<include name="**/*.properties" />
</patternset>
<target name="copy.meta.files" depends="compile">
<copy todir="${build.classes.dir}">
<fileset dir="${build.src.dir}">
<patternset refid="meta.files" />
</fileset>
</copy>
</target>
</project><patternset id="meta.files">
<include name="**/*.xml" />
<include name="**/*.properties" />
</patternset>
<target name="copy.meta.files" depends="compile">
<copy todir="${build.classes.dir}">
<fileset dir="${build.src.dir}">
<patternset refid="meta.files" />
</fileset>
</copy>
</target>
8. Execute target jar for creating jar file from compiled classes
In following Example :
"build.classes.dir" -basedir, use as base folder to create a jar file.
"dist.dir" - destfile is folder.
"dist.dir.jar" - folder under the "dist.dir" , for generating jar files.
"project.name" - use for the generating jar file with major and minor version.
"depends=copy.meta.files" - compile is a target which is execute before jar
(Optional).
(Optional).
<?xml version="1.0" ?>
<project name="TESTWebApp" default="jar" basedir=".">
<target name="jar" depends="copy.meta.files">
<jar destfile="${dist.dir}/${dist.dir.jar}/${project.name}-${app.build.version}.${app.major}.${app.minor}.jar"
basedir="${build.classes.dir}" />
<echo>jar generated :: ${project.name}-${app.build.version}.${app.major}.${app.minor}.jar </echo>
</target>
</project><target name="jar" depends="copy.meta.files">
<jar destfile="${dist.dir}/${dist.dir.jar}/${project.name}-${app.build.version}.${app.major}.${app.minor}.jar"
basedir="${build.classes.dir}" />
<echo>jar generated :: ${project.name}-${app.build.version}.${app.major}.${app.minor}.jar </echo>
</target>
9. Execute target war , for creating war file from jar file
In following Example :
"dist.dir" - destfile is folder.
"dist.dir.jar" - folder under the "dist.dir.jar" , for generating jar files.
"dist.dir.jar" - folder under the "dist.dir.jar" , for generating jar files.
"dist.dir.war" - folder under the "dist.dir" , for generating war files.
"project.name" - use for the generating jar file with major and minor version.
"depends=jar" - compile is a target which is execute before war
(Optional).
(Optional).
<?xml version="1.0" ?>
<project name="TESTWebApp" default="war" basedir=".">
<target name="war" depends="jar">
<war destfile="${dist.dir}/${dist.dir.war}/${project.name}-
${app.build.version}.${app.major}.${app.minor}.war"
webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}" >
<exclude name="WEB-INF/web.xml" />
</fileset>
<lib dir="${dist.dir}/${dist.dir.jar}" />
</war>
<echo>war generated :: ${project.name}-${app.build.version}.${app.major}.${app.minor}.war
</echo>
</target>
9. Execute target war , for creating war file from compiled classes file
In following Example :
"build.classes.dir" - folder under all compile clasess placed.
"dist.dir" - destfile is folder.
"dist.dir.war" - folder under the "dist.dir" , for generating war files.
"project.name" - use for the generating jar file with major and minor version.
"depends=compile" - compile is a target which is execute before war
(Optional).
(Optional).
<?xml version="1.0" ?>
<project name="TESTWebApp" default="war" basedir=".">
<target name="war" depends="compile">
<war destfile="${dist.dir}/${dist.dir.war}/${project.name}-
${app.build.version}.${app.major}.${app.minor}.war"
webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}" >
<exclude name="WEB-INF/web.xml" />
</fileset>
<classes dir="${build.classes.dir}" />
</war>
<echo>war generated :: ${project.name}-${app.build.version}.${app.major}.${app.minor}.war
</echo>
</target>
</project><war destfile="${dist.dir}/${dist.dir.war}/${project.name}-
${app.build.version}.${app.major}.${app.minor}.war"
webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}" >
<exclude name="WEB-INF/web.xml" />
</fileset>
<classes dir="${build.classes.dir}" />
</war>
<echo>war generated :: ${project.name}-${app.build.version}.${app.major}.${app.minor}.war
</echo>
</target>
10. build.proprties
#################################################################################
####### Output Folder Tree Stucture ##############
#################################################################################
dist.dir=c:/Ant/Ant Build Demo/dist
dist.dir.war=war
dist.dir.jar=jar
#################################################################################
####### Project Specific Details ##############
#################################################################################
web.dir=C:/apache-tomcat-6.0.26/webapps/TESTWebApp
web.lib.dir=${web.dir}/WEB-INF/lib
build.classes.dir=${web.dir}/WEB-INF/classes
build.src.dir = ${web.dir}/WEB-INF/src
project.name=TESTWebApp
tomcat.dir=C:/apache-tomcat-6.0.26/
tomcat.web.lib.dir=${tomcat.dir}/lib
project.builder = Shrikant
app.version =1.0
app.name = TESTWebApp
ant.config.xml.home=C:/Ant/Ant Build Demo/apache-ant-1.8.2
10. version.proprties
#################################################################################
####### Version History ##############
#################################################################################
app.build.version=13
No comments:
Post a Comment