ANT Property Files

Properties are a good way to keep your ant tasks customizable. Here is a example of how to use property files.

build.properties

Flex.SDK = /opt/flex_sdk_4
Flex.Source = source
Flex.Build = build
Flex.Working = working

local.properties

Flex.Source = my_custom_source
Flex.Build = my_custom_build
Flex.Working = my_custom_working

build.xml

<?xml version="1.0" encoding="utf-8"?>
<project name="Test" basedir=".">
	<property file="local.properties"/>
	<property file="build.properties"/>
	<echo>${Flex.SDK}</echo>
	<echo>${Flex.Source}</echo>
	<echo>${Flex.Build}</echo>
	<echo>${Flex.Working}</echo>
</project>

Outputs

Buildfile: build.xml
     [echo] /opt/flex_sdk_4
     [echo] my_custom_source
     [echo] my_custom_build
     [echo] my_custom_working

BUILD SUCCESSFUL
Total time: 0 seconds

You’ll notice that I included the local.properties file first and the variables in there are the true values once everything is loaded. I would have thought this would be backwards. But the easy fix for overwriting properties is to switch the load order.

Source Code

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s