Ant Properties File
You can also group all the property values in a separate properties file and include it in the ant build file. Here the build.properties file contains all the property values. Remember the property value is immutable, so if you set a property value in the properties file you cannot change it in the build file. This give more control over the build process.
The build.properties file.
web.dir=WebContent
web.lib.dir=${web.dir}/WEB-INF/lib
build.classes.dir=build/classes
dist.dir=dist
project.name=AntExample3
Use the property task to include the properties file in the Ant build file.
<property file="build.properties" />
Here is the complete build file for your reference.
<?xml version="1.0" ?>
<project name="AntExample3" default="war">
<property file="build.properties" />
<path id="compile.classpath">
<fileset dir="${web.lib.dir}">
<include name="*.jar"/>
</fileset>
</path>
<target name="init" depends="clean">
<mkdir dir="${build.classes.dir}"/>
<mkdir dir="${dist.dir}" />
</target>
<target name="compile" depends="init" >
<javac destdir="${build.classes.dir}" debug="true" srcdir="src">
<classpath refid="compile.classpath"/>
</javac>
</target>
<target name="war" depends="compile">
<war destfile="${dist.dir}/${project.name}.war" webxml="${web.dir}/WEB-INF/web.xml">
<fileset dir="${web.dir}"/>
<lib dir="${web.lib.dir}"/>
<classes dir="${build.classes.dir}"/>
</war>
</target>
<target name="clean">
<delete dir="${dist.dir}" />
<delete dir="${build.classes.dir}" />
</target>
</project>
|