before getting started our ant script you should know development and deployment structures of web application.
lib- all jar
src- all java or POJO
web or WebContent- web folder
etc-config file
dist-
build-
1. create a "build.properties"
root.dir=..
lib.dir=lib
src.dir=src
dist.dir=dist
build.dir=build
web.content=WebContent
build.classpath=build/WEB-INF/classes
project.name=Opgear
2. create a "build.xml" for automated the war deployment
our target
1.clean
2.makedir
3.compile
4.copy dependencies
5.war
< ?xml version="1.0" encoding="UTF-8" standalone="no"? >
< project basedir="." default="build" name="opgear" >
< property file="build.properties"/ >
< property environment="env"/ >
< property name="ECLIPSE_HOME" value="../../eclipse"/ >
< property name="debuglevel" value="source,lines,vars"/ >
< property name="target" value="1.6"/ >
< property name="source" value="1.6"/ >
< path id="java.classpath" >
< pathelement location="bin"/ >
< /path >
< !-- First, I create my classpath (build.classpath) from all the jar files in my lib directory -- >
< path id="build.classpath" >
< fileset dir="lib" >
< include name="**/*.jar" / >
< /fileset >
< /path >
< !-- Deletes or clear the existing build, dist directory-- >
< target name="clean" >
< delete dir="${build.dir}" / >
< delete dir="${build.classpath}" / >
< delete dir="${dist.dir}" / >
< /target >
< !-- Creates the build, docs and dist directory-- >
< target name="makedir" >
< mkdir dir="${build.dir}" / >
< mkdir dir="${build.classpath}" / >
< mkdir dir="${dist.dir}" / >
< /target >
< !-- Compiles the java code -- >
< target name="compile" depends="clean, makedir" >
< echo > Compile the source files< /echo >
< javac srcdir="${src.dir}" destdir="${build.dir}/WEB-INF/classes" classpathref="build.classpath" >
< /javac >
< /target >
< !--copy the compiled classess and webcontent to build dir -- >
< target name="copy" depends="compile" >
< echo > todir ${build.dir} < /echo >
< copy todir="${build.dir}" >
< fileset dir="${web.content}"/ >
< /copy >
< copy todir="${build.dir}/WEB-INF/lib" >
< fileset dir="${lib.dir}"/ >
< /copy >
< /target >
< !--Creates the deployable jar file -- >
< target name="war" depends="copy" >
< echo > Building the war file< /echo >
< war destfile="${dist.dir}/${project.name}.war" webxml="${build.dir}/WEB-INF/web.xml" >
< fileset dir="${build.dir}"/ >
< /war >
< /target >
< target name="build" depends="compile,war" >
< description > Main target< /description >
< /target >
< /project >
No comments:
Post a Comment