本文介绍了使用ant检测操作系统并设置属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据操作系统类型在 ant 任务中设置不同的属性.

I want to set a property in an ant task differently by os type.

属性是一个目录,在 windows 中我希望它是在 unix/linux 中的c:\flag"/opt/flag".

The property is a directory, in windows i want it to be "c:\flag" in unix/linux "/opt/flag".

我当前的脚本仅在我使用默认目标运行时才有效,但为什么呢?

My current script only works when i run it with the default target, but why ?

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

在我所有的蚂蚁目标中,我都添加了一个depends=checksw_path".

In all my ant targets i've added a "depends=checksw_path".

如果我在 Windows 中运行默认目标,我得到了正确的c:\flag",但如果我运行一个非默认目标,我得到调试进入 if_windows 但指令"没有设置保留/opt/flag 的属性.我正在使用蚂蚁 1.7.1.

If i run the default target in windows i've got correctly "c:\flag" but if i run a non default target i've got that the debug goes in the if_windows but the instruction " " does not set the property that remains /opt/flag. I'm using ant 1.7.1.

推荐答案

我使用 -Dsw.root=c:\flag(对于 Windows)或 -Dsw.root= 解决了使用 sw.root 的值执行 ant 任务/opt/superwaba(适用于 Linux).

I solved executing the ant task with the value for sw.root using -Dsw.root=c:\flag (for windows) or -Dsw.root=/opt/superwaba (for linux).

还是谢谢

这篇关于使用ant检测操作系统并设置属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 07:21