Search

Ant Property WAR file creation and Project deploy

The <property> task is used to set the Ant properties. The property value is immutable, once the value is set you cannot change it. To set a property to a specific value you use Name/value assignment.
view source
print?
1.<property name="project.name" value="AntExample2" />
 To set a property to a location you use Name/location assignment.
view source
print?
1.<property name="web.dir" location="WebContent"/>
2.<property name="web.lib.dir" location="${web.dir}/WEB-INF/lib"/>
3.<property name="build.classes.dir" location="build/classes"/>
4.<property name="dist.dir" location="dist"/>
To use the properties surround them with ${}.
The following build file shows how to set and use property values.
view source
print?
01.<?xml version="1.0" ?>
02.<project name="AntExample2" default="war">
03. 
04.<property name="web.dir" location="WebContent"/>
05.<property name="web.lib.dir" location="${web.dir}/WEB-INF/lib"/>
06.<property name="build.classes.dir" location="build/classes"/>
07.<property name="dist.dir" location="dist"/>
08.<property name="project.name" value="AntExample2" />
09. 
10.<path id="compile.classpath">
11.<fileset dir="${web.lib.dir}">
12.<include name="*.jar"/>
13.</fileset>
14.</path>
15. 
16.<target name="init">
17.<mkdir dir="${build.classes.dir}"/>
18.<mkdir dir="${dist.dir}" />
19.</target>
20. 
21.<target name="compile" depends="init" >
22.<javac destdir="${build.classes.dir}" debug="true" srcdir="src">
23.<classpath refid="compile.classpath"/>
24.</javac>
25.</target>
26. 
27.<target name="war" depends="compile">
28.<war destfile="${dist.dir}/${project.name}.war"webxml="${web.dir}/WEB-INF/web.xml">
29.<fileset dir="${web.dir}"/>
30.<lib dir="${web.lib.dir}"/>
31.<classes dir="${build.classes.dir}"/>
32.</war>
33.</target>
34. 
35.<target name="clean">
36.<delete dir="${dist.dir}" />
37.<delete dir="${build.classes.dir}" />
38.</target>
39. 
40.</project>

No comments:

Post a Comment