Recent Posts
Archives

PostHeaderIcon Conditionnal Statement in Jakarta Ant

Sometimes, a Java developer needs a “if-then-else” conditionnal statement in Ant scripts:

Following case is frequently met in Java code:

[java] if (tata == "foo"){     tata = toto; }else{     tata = tata; // useless } 

or less verbose, the so-called ternary operation:

[java]      tata =  (tata == "foo") ? toto : tata; 

Here is an equivalent in Ant script:

[xml]     <target name="default-conditionnal-statement">         <echo>toto : ${toto}</echo>         <condition property="tata" value="${toto}">             <equals arg1="${tata}" arg2="foo" />         </condition>         <echo>tata : ${tata}</echo>     </target> 

Leave a Reply