0

I'd like to execute subant on some condition. something like:

<if>
<equals value="value1" property="${some.property">
<then>
  <subant target="@{target}" failonerror="true" inheritall="false">
    <buildpath refid="some-ref1" />
  </subant>
</then>
<else>
  <subant target="@{target}" failonerror="true" inheritall="false">
          <buildpath refid="some-ref2" />
  </subant>
</else>
</if>

But can't find a way to do it. Read the ant manual and googled, but no solution is found.

Thanks.

Charles
  • 50,943
  • 13
  • 104
  • 142
Vladimir Ivanov
  • 42,730
  • 18
  • 77
  • 103

3 Answers3

1

I believe the error may lie in your equals tag. Instead of using the 'value' and 'propery' attributes, try using 'arg1' and 'arg2', i.e.:

<equals arg1="value1" arg2="${some.property}">

Check out the examples in the ant-contrib doc: http://ant-contrib.sourceforge.net/tasks/tasks/if.html.

If the problem is that your 'if', 'then', and/or 'else' tags are not resolving properly, then you may be missing the ant-contrib libraries. Ant-contrib is not natively included with ant, but you can download it here: http://sourceforge.net/projects/ant-contrib/files/

Per the ant-contrib site (http://ant-contrib.sourceforge.net/), here's what you must do to install ant-contrib:

Option 1: Copy ant-contrib-0.3.jar to the lib directory of your Ant installation. If you want to use one of the tasks in your own project, add the lines

<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

to your build file.

Option 2: Keep ant-contrib-0.3.jar in a separate location. You now have to tell Ant explicitly where to find it (say in /usr/share/java/lib):

<taskdef resource="net/sf/antcontrib/antcontrib.properties">
  <classpath>
    <pathelement location="/usr/share/java/lib/ant-contrib-0.3.jar"/>
  </classpath>
</taskdef>
Justin
  • 1,419
  • 12
  • 14
0

Please look up a <target if="${some.property}>. You may want another target with an unless.

If the property has to do with a file existing, see Ant task to check a file exists?. Even if this is not your main concern, I am sure you can get the idea from the accepted answer.

Community
  • 1
  • 1
rajah9
  • 11,645
  • 5
  • 44
  • 57
0

Do you mean calling another target if so here is

<if> 
<equals value="value1" property="${some.property">
<then>
<antcall target="@{target}" failonerror="true" inheritall="false">
 </then>
<else>
  <antcall target="@{target}" failonerror="true" inheritall="false">


</else>
</if>
eldarerathis
  • 35,455
  • 10
  • 90
  • 93
Jagan
  • 1
  • 1