我想通過os類型以不同的方式在ant任務中設置屬性。使用ant來檢測os並設置屬性
該屬性是一個目錄,在Windows中,我希望它是「c:\ flag」在unix/linux「/ opt/flag」中。
我當前的腳本只適用於當我用默認目標運行它,但爲什麼?
<target name="checksw_path" depends="if_windows, if_unix"/>
<target name="checkos">
<condition property="isWindows">
<os family="windows" />
</condition>
<condition property="isLinux">
<os family="unix" />
</condition>
</target>
<target name="if_windows" depends="checkos" if="isWindows">
<property name="sw.root" value="c:\flag" />
<echo message="${sw.root}"/>
</target>
<target name="if_unix" depends="checkos" if="isLinux">
<property name="sw.root" value="/opt/flag" />
<echo message="${sw.root}"/>
</target>
在我已經添加了我所有的Ant目標 「取決於= checksw_path」。
如果我在Windows中運行默認目標,我已經正確地「c:\ flag」但如果我運行一個非默認目標,我已經調試進入if_windows,但指令「」沒有設置該屬性仍然是/ opt/flag。我正在使用ant 1.7.1。