Date Created: Fri 08-Oct-2010

Related Document Categories:

Get my WebSphere Application Server course here >>

Sample Ant build script that is designed to take an Eclipse based WAR project and manually create a WAR file for distribution by other systems to WebSphere. It is only one way of doing things, but the good thing about this simple approach is that a developer can set up an Ant build project that is independent from the development of the WAR. With a few extra lines this could be made to build an EAR, which is better for enterprise deployment readiness.

<?xml version="1.0" encoding="UTF-8"?>
<project name="Log View EAR build script" default="makewar" basedir=".">
<format property="buildtimestamp" pattern="yyyy-MM-dd'T'HH:mm:ss" />

<condition property="isWindows">
<os family="windows"/>

<condition property="isMac">
<os family="unix"/>

<echo message="==== Eclipse Workdspace Properties ===="/>
<echo message="${workspace_loc}"/>

<property name="root" value=".." />
<echo message="root=${root}"/>

<property name="EARBasePath" value="${root}/LogViewEAR" />
<echo message="EARBasePath=${EARBasePath}"/>

<property name="WARBasePath" value="${root}/LogViewWAR" />
<echo message="WARBasePath=${WARBasePath}"/>

<property name="lib.dir" value="${WARBasePath}/WebContent/WEB-INF/lib" />
<echo message="lib.dir=${lib.dir}"/>

<property name="src.dir" value="${WARBasePath}/src" />
<echo message="src.dir=${src.dir}"/>

<property name="pages.dir" value="${WARBasePath}/WebContent" />
<echo message="pages.dir=${pages.dir}"/>

<echo message="==== Temp Staging Area &amp; Build Properties ===="/>

<property name="package.file" value="LogViewWAR.war" />
<property name="temp.dir" value="c:/temp/antbuild/temp" />
<property name="temp.dir.webcontent" value="${temp.dir}/WebContent" />
<property name="temp.dir.web-inf" value="${temp.dir.webcontent}/WEB-INF" />
<property name="temp.dir.lib" value="${temp.dir.web-inf}/lib" />
<property name="temp.dir.classes" value="${temp.dir.web-inf}/classes" />
<property name="temp.dir.meta-inf" value="${temp.dir.webcontent}/META-INF" />

<property name="dest.dir" value="c:/temp/antbuild/dist/" />

<echo message="===="/>

<target name="mac" if="isMac">
<property file="" />
<echo message="${}, using ${props.file}" />

<target name="windows" if="isWindows">
<property file="" />
<echo message="${}, using ${props.file}" />

<target name="os" depends="windows,mac">
<path id="classpath">
<fileset dir="lib">
<include name="*.jar" />


<target name="clean" depends="">
<echo>=== CLEAN ===</echo>
<delete dir="${temp.dir}" />
<delete dir="${dest.dir}" />

<target name="prepare" depends="clean">
<echo>=== PREPARE ===</echo>
<mkdir dir="${dest.dir}" />
<mkdir dir="${temp.dir}" />
<mkdir dir="${temp.dir.lib}" />
<mkdir dir="${temp.dir.webcontent}" />
<mkdir dir="${temp.dir.meta-inf}" />
<mkdir dir="${temp.dir.web-inf}" />
<mkdir dir="${temp.dir.classes}" />

<!-- BUILD ALL -->
<target name="all" depends="makeear">
<echo>=== BUILD ALL ===</echo>
<delete dir="${build}" />

<!-- Set up a path id for external JARS reference during compilation of WAR Java files-->
<path id="build.classpath">
<fileset dir="C:/WAS7/AppServer/lib/">
<include name="j2ee.jar" />

<fileset dir="${lib.dir}">
<include name="simple-log.jar" />


<!-- COMPILE -->
<target name="compile" depends="prepare">
<echo>=== COMPILE ===</echo>
<javac debug="on" srcdir="${src.dir}" destdir="${temp.dir.classes}">
<classpath refid="build.classpath" />

<compilerarg value="-Xlint:unchecked" />


<!-- PACKAGE WAR File -->
<target name="makewar" depends="compile">
<echo>=== PACKAGE WAR ===</echo>

<echo>copy the config files</echo>
<copy file="${WARBasePath}/WebContent/META-INF/MANIFEST.MF" tofile="${temp.dir.meta-inf}/MANIFEST.MF" overwrite="true" />
<!--<copy file="${WARBasePath}/WebContent/WEB-INF/web.xml" tofile="${temp.dir.web-inf}/web.xml" overwrite="true" />-->

<echo>copy the JAR files</echo>
<copy todir="${temp.dir.lib}">
<fileset dir="${WARBasePath}/WebContent/WEB-INF/lib">
<include name="**/*.jar"/>

<echo>copy the web content</echo>
<copy todir="${temp.dir.webcontent}">
<fileset dir="${WARBasePath}/WebContent/">
<include name="**/*.zul"/>
<include name="**/*.html"/>

<copy todir="${temp.dir.web-inf}">
<fileset dir="${WARBasePath}/WebContent/WEB-INF">
<include name="**/*.xml"/>
<include name="**/*.properties"/>

<echo>Build the WAR file...with all resources in place, create the war file</echo>
<war destfile="${dest.dir}/${package.file}" webxml="${temp.dir.web-inf}/web.xml" basedir="${temp.dir}">

<fileset dir="${temp.dir.webcontent}">
<include name="**/*.xml"/>
<include name="**/*.properties"/>

<classes dir="${temp.dir.classes}" />


<target name="makeear" depends="makewar">
<echo>=== MAKE EAR ===</echo>
<ear earfile="${dest.dir}/HRApplicationEAR.ear" appxml="${EARBasePath}/EarContent/META-INF/application.xml">
<fileset dir="${dest.dir}">
<include name="*.war"/>


<!--<target name="all">
<delete dir="${build}" />

Get my WebSphere Application Server course here >>

Steve Robinson - IBM Champion 2013

About Me

Steve Robinson has been working in IT for over 20 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware.

In January 2013, I was awarded the prestigous 'IBM Champion' accolade.

  • Linked In
  • Twitter
  • About Me
  • My Blog
  • Contact Me

Read my books?

IBM WebSphere Application Server 8.0 Administration Guide

IBM WebSphere Application Server 8.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Application Server 7.0 Administration Guide

WebSphere Categories

Other Categories