如何在ant中检查条件并根据其值打印消息?
这是一小段代码,请看一下,然后按照说明进行操作如何在ant中检查条件并根据其值打印消息?,ant,Ant,这是一小段代码,请看一下,然后按照说明进行操作 <condition property="${param1}"> <or> <istrue value="win-x86"/> <istrue value= "win-x86-client"/> <istrue value= "win-x64"/>
<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>
我希望当ever platform.id包含任何windows系列名称时,它应该打印执行windows系列生成的消息,但问题是,即使该系列是unix,它也会打印此消息
我想要么我没有正确检查情况,要么我犯了其他错误。
有人能帮我解决这个问题吗?看来你误解了: 属性:要设置的属性的名称 尝试使用以下命令: 测试当前操作系统是否属于给定类型
Peter试图解释您必须明确指定属性名称。请尝试以下操作以使代码正常工作:
<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任务中内置的操作系统测试
由于ant 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>
我正在platform.id中传递我自己的值,我想检查它是否为上述三个值之一,然后尝试使用。我想你们没有理解我的问题,我的程序流程与上述完全相同。如果platform.id包含上述三个值中的任何一个,则应打印消息。这就是我想要我的程序做的,我想你们并没有理解我的答案:你们对条件的使用是错误的。property是要设置的属性的名称-如果具有该名称的属性的值为true、yes或on,则不进行检查,并且istrue会进行检查。您需要检查特定的值,因此需要的是equals。文档中有完美的示例,所以我不打算为您编写这些代码。请随时询问您在实现方面是否有困难。请至少使用v1.9.3-另请参阅
<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>