我使用了多个目标来根据操作系统设置变量名。
<target name="checkos">
<condition property="isWindows">
<os family="windows" />
</condition>
<condition property="isUnix">
<os family="unix" />
</condition>
</target>
<target name="if_windows" depends="checkos" if="isWindows">
<property name="path" location="deploy.exe"/>
</target>
<target name="if_unix" depends="checkos" if="isUnix">
<property name="path" location="deploy.sh"/>
</target>
如何在单个目标中设置它。我使用了if和condition,但是它不允许这样做
在ant>= 1.9.1中使用ant 1.9.1引入的if/unless新特性,但由于ant 1.9.1中的bug,您应该使用ant 1.9.3,请参阅此答案了解详细信息
<project
xmlns:if="ant:if"
xmlns:unless="ant:unless"
>
<target name="setos">
<condition property="isWindows">
<os family="windows" />
</condition>
<property name="path" location="deploy.exe" if:true="${isWindows}"/>
<property name="path" location="deploy.sh" unless:true="${isWindows}"/>
</target>
</project>
否则用ant <1.9.1使用如下格式:
<target name="checkos">
<condition property="isWindows">
<os family="windows" />
</condition>
</target>
<target name="if_windows" depends="checkos" if="isWindows">
<property name="path" location="deploy.exe"/>
</target>
<target name="if_unix" depends="checkos" unless="isWindows">
<property name="path" location="deploy.sh"/>
</target>