I am trying to check the ant build script’s argument is set or not. I have tried many way to do this but there is no success. I define the argument with -Dmaindir="../propertyfolderpath".
Here is the code sample that I have tried;
<ac:if>
<equals arg1="@{maindir}" arg2="" />
<ac:then>
<echo message="maindir argument is empty. Current properties will be used." />
<property file="build.properties" />
</ac:then>
<ac:else>
<echo message="maindir = ${maindir}" />
<ac:if>
<ac:available file="${maindir}/build.properties" type="file" />
<ac:then>
<property file="${maindir}/build.properties" />
</ac:then>
<ac:else>
<fail message="${maindir} is not a valid path." />
</ac:else>
</ac:if>
</ac:else>
</ac:if>
- There are three cases;
- Argument might not be defined. Ant should go into first
- Argument defined well.
- Argument defined with wrong path
For 2nd case script is working.
For 3rd case script is working.
But for 1st case, I mean when I dont define maindir argument, ant act like 3rd case. That is my problem.
Why ant act like that?
Maybe you can try setting a default value for the argument?
I tried this and it works, when no argument is passed the value of
${maindir}is[default].