Meyyappan has posted 101 posts at DZone. View Full User Profile

Ant Property Task

06.13.2012
| 18192 views |
  • submit to reddit

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.

<property name="project.name" value="AntExample2" />

 To set a property to a location you use Name/location assignment.

<property name="web.dir" location="WebContent"/>
<property name="web.lib.dir" location="${web.dir}/WEB-INF/lib"/>
<property name="build.classes.dir" location="build/classes"/>
<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.

<?xml version="1.0" ?> 
<project name="AntExample2" default="war">
	
	<property name="web.dir" location="WebContent"/>
	<property name="web.lib.dir" location="${web.dir}/WEB-INF/lib"/>
	<property name="build.classes.dir" location="build/classes"/>
	<property name="dist.dir" location="dist"/>
	<property name="project.name" value="AntExample2" />

	<path id="compile.classpath">
		<fileset dir="${web.lib.dir}">
			<include name="*.jar"/>
		</fileset>
	</path>
	
	<target name="init">
		<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>

You can download the build file here.

Build File:  Download

Project:  Download

Published at DZone with permission of its author, Meyyappan Muthuraman.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Rabindra Kumar replied on Mon, 2013/07/15 - 8:13am

 good


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.