它看起來像ANT <condition>
可以測試的名字,家庭&版本的操作系統:
基於該鏈接的,也有涉及到操作系統的一些特性,我們可以查詢。一個是在普通代碼中使用的正常family
屬性:
<!-- CHECK FOR WINDOWS FAMILY OS -->
<condition property="is_windows">
<os family="windows"/>
</condition>
我ANT的版本不適用${os.family}
打印出解析值。
還有:
- os.name < ---這就是你需要檢查
- os.arch
- os.version
的一個
這裏有一個演示腳本,我提出來顯示這些屬性的使用:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Test" default="build" >
<!-- CHECK FOR WINDOWS FAMILY OS -->
<condition property="is_windows">
<os family="windows"/>
</condition>
<condition property="is_windows_7">
<os name="Windows 7"/>
</condition>
<!-- DISPLAYS WINDOWS OS -->
<target name="display_windows" if="is_windows" >
<echo message="OS Family is: Windows" />
</target>
<target name="build" >
<antcall target="display_windows" />
<echo message="OS Name is: ${os.name}" />
<echo message="OS Architecture is: ${os.arch}" />
<echo message="OS Version is: ${os.version}" />
</target>
</project>
因爲回答這個問題,上面的代碼已經被提升到我們的生產版本的系統,它是跨Windows &蘋果提供共享功能。
@thekbb取得了良好的建議,刪除<antcall target="display_windows" />
,並更新目標定義取決於display_windows
按下面的代碼:
<target name="build" depends="display_windows">
<echo message="OS Name is: ${os.name}" />
<echo message="OS Architecture is: ${os.arch}" />
<echo message="OS Version is: ${os.version}" />
</target>
此基礎上antcall
啓動一個新的實例的事實的螞蟻在一個新的JVM中。一些用戶可能會發現這種優化更容易理解;出於性能原因,其他人可能會這樣做。
可能重複的[使用螞蟻來檢測操作系統和設置屬性](http://stackoverflow.com/questions/453170/using-ant-to-detect-os-and-set-property) – oers 2012-03-05 14:25:32
我已經檢查,但我想要做的是檢查它的XP,Vista或Win7的其他選項只會讓你知道,如果它的窗戶。 – Nathan 2012-03-07 16:15:34
@Nathan - 你有沒有運氣使用我的答案?請標記爲已接受,或者給我留言,以便我可以提供更多幫助。這種技術被用在我們的生產構建系統中,但它可能無法解決你的問題。 – 2013-07-01 09:54:58