How to use a condition element in ant to set another property?

I have build.xml for use with ant, and I'm trying to put a condition on the target:

First, I set a property here, which works fine:

<condition property="isWindows"> <os family="windows"/> </condition> 

Then I try to use it for the purpose:

 <target name="-post-jar"> <condition property="isWindows" value="true"> <!-- set this property, only if isWindows set --> <property name="launch4j.dir" location="launch4j" /> </condition> <!-- Continue doing things, regardless of property --> <move file="${dist.jar.dir}" tofile="myFile"/> <!-- etc --> </target> 

I get an error: “the condition does not support the nested element“ property. ”There are questions: how to correctly place the condition inside the target and why is the error related to the“ nested ”property?

+4
source share
2 answers

condition used to define a property, but not to perform some action based on the value of the property.

Use a target with an if or unless to perform some tasks based on the value of the property.

+3
source

The criteria for condition are nested inside the condition element.

You specify the property that you want to set using the property attribute, and the value when the condition is met using the value attribute in the condition element. In addition, you can set the value for the property; the condition is not satisfied with the else attribute.

To check if a property is set as a criterion for condition , use isset

 <condition property="isWindows"> <os family="windows"/> </condition> <target name="-post-jar"> <!--Only set property if isWindows --> <condition property="launch4j.dir" value="launch4j"> <isset property="isWindows"/> </condition> <!-- Continue doing things, regardless of property --> <move file="${dist.jar.dir}" tofile="myFile"/> <!-- etc --> </target> 
0
source

All Articles