Search code examples
javaantbuild-process

Ant: Referencing dynamic properties


I want to use the same ant script to do a build in either my local windows environment or on our redhat build server.

I have a variable 'buildDirectory' in two files (build_unix.properties & build_windows). I want to set variables depending on the environment.

<osfamily property="os.family"/>
<property file="./build_${os.family}.properties" />
<property name="tmp-base.folder" value="${buildDirectory}/tmp/"/>

I also tried

<if>
    <os family="unix"/>
    <then>
        <property file="./build_unix.properties" />
    </then>
    <else>
        <property file="./build_windows.properties" />
    </else>
</if>

Any ideas?


Solution

  • I would expect your if...then...else version to work. As it apparently isn't I would add some extra echo's to make sure your build is doing what you think it is doing.

    1. An echo inside the then and the else would let you know for certain what path is being executed.
    2. Add a prefix to the properties (e.g. <property file="..." prefix="test" />) and then add an <echoproperties prefix="test" /> to ensure the properties you think are being loaded are.