How to find out the current platform using Ant
I'm开发者_C百科 creating an installer using Ant and I'm facing a problem. I need to create a file with different extension depending on the platform (Unix or Windows) but I don't know how to get the current platform from Ant.
Can anyone help me? Thank you in advance, Joshua.
Is this something you're attempting to do in a build.xml
? The <condition>
task supports the condition os
which can help you determine the platform for your install script:
<condition property="is.windows">
<os family="windows"/>
</condition>
Then you can split tasks into Unix and Windows:
<target name="deploy"
depends="deploy.unix, deploy.windows">
<yadda/>
<yadda/>
<yadda/>
</target>
<target name="deploy.unix"
unless="is.windows">
<yadda/>
<yadda/>
<yadda/>
</target>
<target name="deploy.windows"
if="is.windows">
<yadda/>
<yadda/>
<yadda/>
</target>
The deploy
target will call both deploy.unix
and deploy.windows
. However, the deploy.unix
target will be skipped if it's a Windows system and deploy.windows
will be skipped if it's not a Windows system.
And, if you're using the <exec>
task, you can also specify if you're running Windows or Unix:
<exec executable="${unix.program}"
osfamily="unix"/>
<exec executable="${windows.program}"
osfamily="windows"/>
精彩评论