如何检测ANT Windows操作系统 [英] How to detect the windows OS in ANT

查看:158
本文介绍了如何检测ANT Windows操作系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Ant来编译Java应用程序。问题是,有些开发者是在Win 7和其他人都在XP和Vista。编译的部分是建立使用WIX的微星,在WIN7这是一个目录和XP和Vista它在另一个。

I'm using ant to compile a Java application. The problem is some of the devs are on win 7 and others are on xp and vista. Part of the compiling is to build an msi using WIX, on win7 this is one directory and on xp and vista it's in another.

Ant任务控制在Maven的。我告诉蚂蚁Windows操作系统的之间的区别是有条件的标签设置的WiX目录的方式后我。任何想法?

The ant task is controlled in Maven. I'm after a way of telling the difference between windows os's in ant with a conditional tag to set the wix directory. Any ideas?

我知道这将是格式为:

<if>
   <condition property="isWin7">
    Check for windows 7
   </condition>
   <then>
    set wix path to win 7 installation
   </then>
   <else>
    set to vista/xp wix installation
   </else>
 </if>

任何帮助将是巨大的。

Any help would be great.

推荐答案

它看起来像ANT &lt;条件&GT; 可以测试名称,家人和放大器;操作系统版本:

It looks like the ANT <condition> can test for name, family & version of operating system:

  • Ant Tasks - conditions

根据该链接,也有相关的操作系统,我们可以查询一些属性。一个是正​​常的家庭在共同code使用的属性:

Based on that link, there are some properties related to OS that we can query. One is the normal family property used in the common code:

<!-- CHECK FOR WINDOWS FAMILY OS -->
<condition property="is_windows">
    <os family="windows"/>
</condition>

我的ANT的版本不打印出一个解析值 $ {os.family}

还有:


  • os.name &LT; ---这就是你需要检查一个

  • os.arch

  • os.version

  • os.name <--- this is the one you need to check
  • os.arch
  • os.version

下面是我提出来说明如何使用这些特性的演示脚本:

Here's a demo script I made to show the use of these properties:

<?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>

由于在回答这个问题时,code上面已经晋升为我们的生产构建系统,它是跨Windows和放大器提供共享功能; Mac电脑。

Since answering this question, the code above has been promoted to our production build system, where it is providing shared functionality across Windows & Mac.

@thekbb 取得了良好的建议,删除&LT; antcall目标=display_windows /&GT; ,并更新目标定义取决于 display_windows 按下面的code:

@thekbb made a good suggestion to remove the <antcall target="display_windows" />, and update the target definition to depend on display_windows as per the below code:

    <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蚂蚁的新实例。有些用户可能会发现这种优化更容易理解;其他人可能要出于性能的考虑这样做。

This based on the fact that antcall launches a new instance of ant in a new JVM. Some users may find this optimisation easier to understand; others may want to do this for performance reasons.

这篇关于如何检测ANT Windows操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆