2011-04-19 75 views
2

我有脚本不到风度工作becouse一次设置属性成为不可写ANT如何在Ant 1.8中使用词汇范围属性?

<target name="test" > 

    <fileset id="dir1" dir="./dir1"/> 
    <fileset id="dir2" dir="./dir2"/> 

    <pathconvert property="path.converted" refid="dir1"/> 
    <echo message="${path.converted}"/> 
    <property name="path.converted" value="set this property manually"/> 
    <echo>${path.converted}</echo> 
    <pathconvert property="path.converted" refid="dir2"/> 
    <echo message="${path.converted}"/> 
</target> 

总是回荡相同的结果,但我想这是呼应不同

我在Apache Ant的1.8.0版本阅读,该

词法作用域局部特性,即 性质仅是一个目标,连续块或类似 环境内限定 。这是非常有用的 ,其中 宏现在可以定义临时 属性,该属性将在 任务完成后消失。

如何使用它们?

回答

4

我找到了解决办法。使用local task

<target name="direct" depends=""> 

    <fileset id="dir1" dir="./dir1"/> 
    <fileset id="dir2" dir="./dir2"/> 

    <!--<property name="path.converted" value="0"/>--> 
    <local name="path.converted"/> 

    <pathconvert property="path.converted" refid="dir1"/> 
    <echo message="${path.converted}"/> 
    <local name="path.converted"/> 
    <property name="path.converted" value="0"/> 

    <echo>${path.converted}</echo> 
    <local name="path.converted"/> 
    <pathconvert property="path.converted" refid="dir2"/> 
    <echo message="${path.converted}"/> 

</target> 
+0

stackoverflow message:你可以在2天内接受你自己的答案 – popalka 2011-04-19 13:41:38

0

我会简单地使用不同的名称为path.converted上面的例子。
path.converted.1,path.converted.2等

,如果您已经创建了你一定要使用当地任务,使物业当地一个macrodef。