Search

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.

1.web.dir=WebContent
2.web.lib.dir=${web.dir}/WEB-INF/lib
3.build.classes.dir=build/classes
4.dist.dir=dist
5.project.name=AntExample3
 Use the property task to include the properties file in the Ant build file.

1.<property file="build.properties" />
Here is the complete build file for your reference. 

01.<?xml version="1.0" ?>
02.<project name="AntExample3" default="war">
03. 
04.<property file="build.properties" />
05. 
06.<path id="compile.classpath">
07.<fileset dir="${web.lib.dir}">
08.<include name="*.jar"/>
09.</fileset>
10.</path>
11. 
12.<target name="init" depends="clean">
13.<mkdir dir="${build.classes.dir}"/>
14.<mkdir dir="${dist.dir}" />
15.</target>
16. 
17.<target name="compile" depends="init" >
18.<javac destdir="${build.classes.dir}" debug="true" srcdir="src">
19.<classpath refid="compile.classpath"/>
20.</javac>
21.</target>
22. 
23.<target name="war" depends="compile">
24.<war destfile="${dist.dir}/${project.name}.war"webxml="${web.dir}/WEB-INF/web.xml">
25.<fileset dir="${web.dir}"/>
26.<lib dir="${web.lib.dir}"/>
27.<classes dir="${build.classes.dir}"/>
28.</war>
29.</target>
30. 
31.<target name="clean">
32.<delete dir="${dist.dir}" />
33.<delete dir="${build.classes.dir}" />
34.</target>
35. 
36.</project>

No comments:

Post a Comment