我想通过os类型以不同方式设置ant任务中的属性.
该属性是一个目录,在windows中我希望它在unix/linux"/ opt/flag"中是"c:\ 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>
Run Code Online (Sandbox Code Playgroud)
在我的所有蚂蚁目标中,我添加了"depends = checksw_path".
如果我在Windows中运行默认目标我已经正确地"c:\ flag"但是如果我运行非默认目标我已经得到了调试进入if_windows但是指令""没有设置剩余的属性/选择/标志.我正在使用ant 1.7.1.
Dre*_*ejc 23
将您的状况移出<target />
,因为您的目标可能未被调用.
<condition property="isWindows">
<os family="windows" />
</condition>
<condition property="isLinux">
<os family="unix" />
</condition>
Run Code Online (Sandbox Code Playgroud)
小智 12
您需要为属性设置值"true"才能使if条件生效.请参阅以下代码:
<target name="checkos">
<condition property="isWindows" value="true">
<os family="windows" />
</condition>
<condition property="isLinux" value="true">
<os family="unix" />
</condition>
</target>
Run Code Online (Sandbox Code Playgroud)
HTH,Hari
我用过这个脚本,对我来说效果很好:
<project name="dir" basedir=".">
<condition property="isWindows">
<os family="windows" />
</condition>
<condition property="isUnix">
<os family="unix" />
</condition>
<target name="setWindowsRoot" if="isWindows">
<property name="root.dir" value="c:\tmp\" />
</target>
<target name="setUnixRoot" if="isUnix">
<property name="root.dir" value="/i0/" />
</target>
<target name="test" depends="setWindowsRoot, setUnixRoot">
<mkdir dir="${root.dir}" />
</target>
</project>
Run Code Online (Sandbox Code Playgroud)
如果要根据操作系统设置该单个属性,可以直接设置它,而无需创建任务:
<condition property="sw.root" value="c:\flag">
<os family="windows" />
</condition>
<condition property="sw.root" value="/opt/flag">
<os family="unix" />
</condition>
<property name="sw.root" value="/os/unknown/"/>
Run Code Online (Sandbox Code Playgroud)
ege*_*ato -2
我使用 -Dsw.root=c:\flag (对于 Windows)或 -Dsw.root=/opt/superwaba (对于 Linux)解决了使用 sw.root 的值执行 ant 任务的问题。
不管怎样,谢谢
归档时间: |
|
查看次数: |
53316 次 |
最近记录: |