我的脚本无法工作,因为属性一旦设置就变得不可写
<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/