Using Environment Properties In Ant

Tinking around with Ant I found out you can reference system environment properties within your build file.

So in Windows for example you can run SET at the command line and get a long list of properties:


U:\set
ALLUSERSPROFILE=C:\Documents and Settings\All Users
ANT_HOME=D:\ant
APPDATA=C:\Documents and Settings\priestj\Application Data

You can easily reference these in your build file – first set property environment to “env”:

<property environment="env"/>

Now we’ll add some of our Windows system properties (note these are case sensitive!):

<echo>evn.ALLUSERSPROFILE:  ${env.ALLUSERSPROFILE}</echo>
<echo>evn.ANT_HOME:  ${env.ANT_HOME}</echo>
<echo>env.APPDATA: ${env.APPDATA}</echo>

Running this we can see these properties are picked up by Ant!

Buildfile: D:\build.xml
echo:
[echo] env.ALLUSERSPROFILE:   C:\Documents and Settings\All Users
[echo] env.ANT_HOME:   C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910
[echo] env.APPDATA:   C:\Documents and Settings\priestj\Application Data
Recent Related Posts

3 thoughts on “Using Environment Properties In Ant

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>