我想在某些条件下执行subant。类似于:
<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>但是找不到方法去做。阅读ant手册并搜索,但没有找到任何解决方案。
谢谢。
发布于 2011-04-27 01:18:38
我相信错误可能出在你的equals标签上。不使用'value‘和'propery’属性,而是尝试使用'arg1‘和'arg2',即:
<equals arg1="value1" arg2="${some.property}">查看ant-contrib文档中的示例:http://ant-contrib.sourceforge.net/tasks/tasks/if.html。
如果问题是您的' If‘、' then’和/或'else‘标记没有正确解析,那么您可能缺少ant-contrib库。Ant-contrib本身并不包含在ant中,但您可以在此处下载它:http://sourceforge.net/projects/ant-contrib/files/
根据ant-contrib站点(http://ant-contrib.sourceforge.net/),以下是安装ant-contrib必须执行的操作:
选项1:将ant-contrib-0.3.jar复制到Ant安装的lib目录。如果要在自己的项目中使用其中一个任务,请添加以下行
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>添加到构建文件中。
选项2:将ant-contrib-0.3.jar放在单独的位置。现在您必须显式地告诉Ant在哪里可以找到它(比如在/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>发布于 2011-04-27 01:17:32
请查找<target if="${some.property}>。您可能需要另一个具有unless的目标。
如果该属性与现有文件有关,请参见Ant task to check a file exists?。即使这不是你的主要关注点,我相信你也可以从被接受的答案中得到答案。
发布于 2011-04-27 01:18:06
你的意思是调用另一个目标,如果是的话,这里是
<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>https://stackoverflow.com/questions/5793898
复制相似问题