Ant Template for Java Web Application

Suppose you have a Java web application that has structure as follow:

- Project
...- src
.....+ com
...- war
......- WEB-INF
.........+ classes
.........+ jsp
.........+ css
......+ images

src is the source folder.
src/ contains all settings related to JDBC connection.
src/log4j.xml contains all settings related to logging properties.
war/WEB-INF/classes is the folder where the compiled java class files will be put into.
war/WEB-INF/jsp is the folder that contains all JSP file or velocity/freemarker template (if you use any).
war/WEB-INF/css is the folder that contains all CSS file.
war/WEB-INF/applicationContext.xml is the spring configuration file.
war/images is the folder that contain all images file
build.num is an ant generated file for helping incrementing the build number.
build.xml is the ant build file. is the ant properties file.
MANIFEST.MF is the generated manifest file.

Below is an example of the build.xml file for a simple, flexible and sufficient solution of project build file.

And here is the file.

For a copy paste, the text will be provided below:

<?xml version="1.0"?>
<project name="Admin" default="all" basedir=".">
<property file="" />
<path id="classpath">
<fileset dir="${project.lib.dir}">
<include name="**/*.jar" />

<target name="clean" depends="clean-class">
<delete dir="${dist.dir}" />

<target name="clean-class" description="clean all classes">
<delete dir="${build.dest}" />

<target name="compile" description="compile src">
<mkdir dir="${build.dest}" />
<javac source="1.5" target="1.5" srcdir="${src.dir}" destdir="${build.dest}" debug="true">
<classpath refid="classpath" />
<copy todir="${build.dest}">
<fileset dir="${src.dir}">
<exclude name="**/*.java" />

<!-- Create binary distribution -->
<target name="dist" description="Create binary distribution">
<buildnumber file="build.num" />
<format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss" />
<manifest file="MANIFEST.MF">
<attribute name="Built-By" value="${}" />
<attribute name="Implementation-Version" value="${version.num}.${build.number}" />
<attribute name="Built-Date" value="${TODAY}" />
<mkdir dir="${dist.dir}" />
<copy todir="${dist.dir}/${project.distname}.war">
<fileset dir="${war.dir}" />
<fileset file="MANIFEST.MF" />
<target name="all" depends="clean,compile,dist" />



1 comments: (+add yours?)

william said...

Awesome project, Mel! Wow! I love your idea with new use of digi-images! Thank you for sharing tutorial, templates and your wonderful inspiration! more templates easy to download