scripting - ANT 如何使用 Ant 1.8 中的词法作用域属性?

标签 scripting ant

我的脚本无法工作,因为属性一旦设置就变得不可写

<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 版本中读到,

Lexically scoped local properties, i.e. properties that are only defined inside a target, sequential block or similar environment. This is very useful inside of s where a macro can now define a temporary property that will disappear once the task has finished.

如何使用它们?

最佳答案

我找到了解决方案。使用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>

关于scripting - ANT 如何使用 Ant 1.8 中的词法作用域属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5716769/

相关文章:

c++ - 使 C++ 应用程序可编写脚本

ant - 使用不同的参数多次调用ant目标

scripting - 脚本和编程语言之间的区别

linux - 从 shell 脚本获取完整命令

ant - 在 ant 任务 Exec 中,为什么 <arg value ="/c"/> 为可执行文件 ="cmd"提供?其他可能的可执行文件是什么?

ant - 如何在 ant(1) 中执行此 makefile(4) 规则?

带有ant的java版本控制系统

ant - 如何使用 Ant 'input' 任务读取多行值?

windows - "Unix shell"- Windows 下的类似脚本

caching - JMeter - 何时不使用缓存编译脚本(如果可用)