tags:

views:

45

answers:

1

I have a question regarding ANT and its treatment of environment variables. To illustrate I have a small sample.

Given the ANT file test.xml:

    <property environment="env"/>

    <target name="testProps">
            <echo message="${env.MyEnvVar}"/>
            <echo message="${MY_PROPERTY}"/>
    </target>

And the properties file test.props:

MY_PROPERTY=${env.MyEnvVar}

Now set the environment variable MyEnvVar to some value (foo in my case) and run the command line:

ant -f test.xml -propertyfile test.props testProps

The output I get is:

 [echo] foo
 [echo] ${env.MyEnvVar}

What I would like to know is whether there is any way to structure the input properties file such that I get

 [echo] foo
 [echo] foo

That is I would like to name an environment variable in the properties file which is replaced within the ANT script. Note - I know how to access environment variables directly (as is done here). What I need to do is make use of a set of ANT scripts that expect one collection of properties in an environment that defines the same properties using different names. Thus the thought of "bridging" them in a properties file.

I am using ANT 1.6.5.

+1  A: 

You need to read the test.props property file after the environment - you could do so using another property task, i.e. add

<property file="test.props" />

after your existing property environment task.

In full:

<property environment="env" />
<property file="test.props" />

<target name="testProps">
    <echo message="${env.MyEnvVar}"/>
    <echo message="${MY_PROPERTY}"/>
</target>

When you supply the properties file on the command line this gets processed before the content of the build, but at that time ${env.MyEnvVar} is not yet set.

martin clayton
Not exactly what I hoping for, but it does work. Have to see if I can make this work. Thanks for the info.
sfitts