Click to search Andy Jarrett.co.uk RSS feed

Loading Twitter

Ant: Passing attributes to Build.xml

Critter on a previous post asked "if you can pass in attributes to the build.xml file?" From the Terminal this is as easy as adding another argument "-D".

-D<property>=<value>
This will update a property in you build.xml file with the value you passed in

For example you would use something similar to

view plain print about
1ant -buildfile ~/desktop/build.xml -DechoMsg=NewEchoMessage

Putting this into practice here is a sample build.xml which I am going to save to my Desktop

view plain print about
1<?xml version="1.0" encoding="UTF-8"?>
2<project name="myProject" default="runEcho" basedir=".">
3
4    <property name="echoMsg" value="I am the original message" />
5
6 <target name="runEcho">
7<!-- Simply echo's a message to the screen -->
8 <echo message="${echoMsg}"/>
9 </target>
10</project>

From the Terminal no run

view plain print about
1ant -buildfile ~/desktop/build.xml -DechoMsg='I overwrite the echo message'

In your terminal window you should see something like

view plain print about
1Buildfile: [PATH TO BUILD FILE]build.xml
2
3runEcho:
4[echo] I overwrite the echo message
5
6BUILD SUCCESSFUL
7Total time: 0 seconds

Comments Comments (3) | Print Print | Send Send | 5457 Views

Nice one mate.

I've taken the old Model-Glue Ant script you had and modified it a bit.. I've downloaded the latest and placed it on my computer.. made these modification: @modelglueapplicationtemplate@ to all the necessary files..

so now I can call my build.xml and pass in the directory name where I want M-G to be built..
I also use the Ant input task with the addproperty attribute quite a bit. (http://ant.apache.org/manual/CoreTasks/input.html) If you use Eclipse to run your build files you get a nice prompt box to enter your property value.
My preference has always been to create a build.properties file and include that in my build.xml file. I don't have a sample handy or I'd include some syntax, but I tend to use this approach for all of my deployment scripts .
BlogCFC by Raymond Camden + Twitter @AndyJ + ColdFusion jobs + Contact Me + Snippets/Downloads + RSS .