I am only using apache-ant
and not ant-contrib
I have an ant
target
<target name="stop" depends="init" >
...
</target>
In which i want to invoke exec
task.
If the value of a variable HOST_NAME
is all
<exec executable="${executeSSH.shell}" >
<arg value="-h ${HOST_NAME}" />
<arg value="-i ${INSTANCE}" />
<arg value="-w 10" />
<arg value="-e ${myOperation.shell} " />
<arg value=" -- " />
<arg value="${INSTANCE} ${USERNAME} ${PASSWORD}" />
</exec>
If the value of a variable HOST_NAME
is anything else
<exec executable="${executeSSH.shell}">
<arg value="-h ${HOST_NAME}" />
<arg value="-i ${INSTANCE}" />
<arg value="-e ${myOperation.shell} " />
<arg value=" -- " />
<arg value="${INSTANCE} ${USERNAME} ${PASSWORD}" />
</exec>
But i would like to write only one task and not to repeatexec
. I have used HOST_NAME
parameter but what to do about the second parameter -w 10
which is different in both calls.
I have tried a couple of ways by searching on SO by using condition
and if else
but nothing seems to be applicable for exec
or arg
.
To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.
Properties are passed to the new target using nested <param> elements. An investigation of the Ant source code reveals that antcall instantiates and calls the ant task using the current buildfile. This means that a new project instance is created and properties work the same as they do for ant .
Apache ANT is a Java based build tool from Apache Software Foundation. Apache ANT's build files are written in XML and they take advantage of being open standard, portable and easy to understand. This tutorial will teach you how to use Apache ANT to automate the build and deployment process in simple and easy steps.
You can use the condition task:
<condition property="my.optional.arg" value="-w 10" else="">
<equals arg1="${HOST_NAME}" arg2="all" />
</condition>
<exec executable="${executeSSH.shell}" >
<arg value="-h ${HOST_NAME}" />
<arg value="-i ${INSTANCE}" />
<arg line="${my.optional.arg}" />
<arg value="-e ${myOperation.shell} " />
<arg value=" -- " />
<arg value="${INSTANCE} ${USERNAME} ${PASSWORD}" />
</exec>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With