Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use the condition element in ant to set another property?

Tags:

java

ant

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

First I set the property here which works OK:

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

Then I try to use it in the target:

<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'm getting an error: "condition doesn't support the nested "property" element." The questions are : How do I correctly put a condition inside a target and why is the error referring to a 'nested' property?

like image 222
Pete855217 Avatar asked Aug 03 '11 13:08

Pete855217


People also ask

Where are ant properties set?

The <property> task is used to set the Ant properties. The property value is immutable, once the value is set you cannot change it. To set a property to a specific value you use Name/value assignment. To set a property to a location you use Name/location assignment.


1 Answers

condition is used to define a property, but not to execute some actions based on the value of a property.

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

like image 184
JB Nizet Avatar answered Oct 07 '22 22:10

JB Nizet