简体   繁体   中英

Setting Environment variable using ANT scripts

I have set my ANT_HOME to older version of ANT for my compilation of Java projects.

For my deployment of other applications to server machines, I have another ANT location called ANT2.

Before deployment of files, I would like to set my ANT_HOME to ANT2 and for this purpose I have the following ANT script

<target name="run">
     <exec executable="cmd" failonerror="true">
            <env key="ANT_HOME" value="D:\apps\apache-ant-1.8.4"/>
            <arg value="/c"/>
        </exec>
        <property environment="env"/>
    <echo message="${env.ANT_HOME}"/>
</target> 

However when I execute the above, my ANT home doesn't change to D:\\apps\\apache-ant-1.8.4 instead ANT_HOME displays as D:\\apps\\old\\ant

What am I doing wrong and how could I resolve this issue?

this code is not executed in child process

echo message="${env.ANT_HOME}"

so it shows ANT_HOME from current environment (which is not set to D:\\apps\\apache-ant-1.8.4). You should print ANT_HOME from inside cmd app to see its value in child process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM