这是一个小的代码,请给看看它,然后按照说明....
<condition property="${param1}">
<or>
<istrue value="win-x86"/>
<istrue value= "win-x86-client"/>
<istrue value= "win-x64"/>
</or>
</condition>
<target name="Mytarget" if="${param1}">
<echo message="executing windows family build:::${param1}"/>
</target>
<target name="print.name" >
<antcall target="win-x86-build">
<param name="param1" value="${platform.id}"/>
</antcall>
</target>
我想,当过platform.id包含任何Windows家族的名字应该打印邮件EXECUTING WINDOWS FAMILY BUILD
但问题是,它是打印,即使家人是UNIX此消息。
我想无论是我没有正确地检查条件,否则我正在做一些其他的错误。
有人可以帮我这个好吗?
彼得试图解释,你必须明确指定属性名称。 请尝试以下方法让你的代码工作:
<project name="demo" default="Mytarget">
<condition property="windoze">
<or>
<equals arg1="${param1}" arg2="win-x86"/>
<equals arg1="${param1}" arg2="win-x86-client"/>
<equals arg1="${param1}" arg2="win-x64"/>
</or>
</condition>
<target name="Mytarget" if="windoze">
<echo message="executing windows family build:::${param1}"/>
</target>
</project>
一个更好的解决办法是利用内置ANT操作系统的测试条件的任务。
<project name="demo" default="Mytarget">
<condition property="windoze">
<os family="windows"/>
</condition>
<target name="Mytarget" if="windoze">
<echo message="executing windows family build:::${os.name}-${os.arch}-${os.version}"/>
</target>
</project>
由于蚂蚁1.9.1,你可以这样做:
<project name="tryit" xmlns:if="ant:if" xmlns:unless="ant:unless">
<exec executable="java">
<arg line="-X" if:true="${showextendedparams}"/>
<arg line="-version" unless:true="${showextendedparams}"/>
</exec>
<condition property="onmac">
<os family="mac"/>
</condition>
<echo if:set="onmac">running on MacOS</echo>
<echo unless:set="onmac">not running on MacOS</echo>
</project>
文章来源: How check for a condition in ant and depending on its value print a message?