gpt4 book ai didi

ant - Ant antcall定义属性的目标

转载 作者:行者123 更新时间:2023-12-03 12:44:56 25 4
gpt4 key购买 nike

在Ant中,我想定义一个定义属性的目标(称为A),并从另一个目标(称为antcall)对其进行B。我希望目标B在调用目标A之后,可以访问目标A中定义的属性。

例如:

<target name="B">
<antcall target="A" inheritAll="true" inheritRefs="true" />
<echo>${myprop}</echo>
</target>
<target name="A">
<property name="myprop" value="myvalue" />
</target>

但是,它不起作用,并且 <echo>${myprop}</echo>不打印 myvalue(我认为是因为 myprop中未定义 B属性)。

有什么办法吗?

最佳答案

根据Apache Ant FAQ:

    <target name="cond" depends="cond-if"/>

<target name="cond-if" if="prop1">
<antcall target="cond-if-2"/>
</target>

<target name="cond-if-2" if="prop2">
<antcall target="cond-if-3"/>
</target>

<target name="cond-if-3" unless="prop3">
<echo message="yes"/>
</target>
Note: <antcall> tasks do not pass property changes back up to the environment they were called from, so you wouldn't be able to, for example, set a result property in the cond-if-3 target, then do <echo message="result is ${result}"/> in the cond target.
在这方面,使用antcall要做您想做的事 是不可能的

========== 编辑 ===========

尝试 antcallback:AntCallBack与标准的“antcall”任务相同,除了它允许在被调用目标中设置的属性在调用目标中可用。
http://antelope.tigris.org/nonav/docs/manual/bk03ch20.html

从上一页粘贴的示例代码:
    <target name="testCallback" description="Test CallBack">
<taskdef name="antcallback" classname="ise.antelope.tasks.AntCallBack" classpath="${antelope.home}/build" />
<antcallback target="-testcb" return="a, b"/>
<echo>a = ${a}</echo>
<echo>b = ${b}</echo>
</target>

<target name="-testcb">
<property name="a" value="A"/>
<property name="b" value="B"/>
</target>

关于ant - Ant antcall定义属性的目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5275682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com