Ant 蚂蚁嵌套宏调用

Ant 蚂蚁嵌套宏调用,ant,macrodef,Ant,Macrodef,我想从另一个宏的元素内部调用一个宏。 假设我有以下宏: <macrodef name="jc"> <attribute name="name" /> <attribute name="destdir" /> <element name="fileset-list" optional="false" /> <sequential> <jar destfile="@{destdir}${

我想从另一个宏的元素内部调用一个宏。 假设我有以下宏:

<macrodef name="jc">
    <attribute name="name" />
    <attribute name="destdir" />
    <element name="fileset-list" optional="false" />
    <sequential>
        <jar destfile="@{destdir}${file.separator}@{name}.jar" update="false">
            <fileset-list />
            <manifest>
                <attribute name="Manifest-Version" value="1.0" />       
            </manifest>
        </jar>
    </sequential>
</macrodef>

什么是错误的?< /P> < p>您可以尝试在宏宏“jc”中生成宏调用,并将文件集路径视为附加属性

<macrodef name="jc">
    <attribute name="name" />
    <attribute name="destdir" />
    <attribute name="fileset.path.to.consider" />
    <sequential>
        <jar destfile="@{destdir}${file.separator}@{name}.jar" update="false">
            <defaultfs path="@{fileset.path.to.consider}"/>
            <manifest>
                <attribute name="Manifest-Version" value="1.0" />
            </manifest>
        </jar>
    </sequential>
</macrodef>

然后,您的主宏调用可能如下所示:

<jc destdir="${dir.build.jar}" name="thejar" fileset.path.to.consider="org/path/inner"/>


(未测试,您可以尝试一下)

编写“jar”ANT任务并不是为了支持“defaultfs”XML元素。ANT中的宏有些不同,它们的行为更像模板。你是对的,但我的要求是以更广泛的方式使用jc,我有一些使用类似文件集构建的jar。宏是否只计算一次?我有一个类似的例子,我想在宏的(隐式)元素参数中使用宏。还没有弄清楚如何——或者如果可能的话——在外部宏之前计算内部宏。如果你能找到答案,我绝对感兴趣!(不,组合这两个宏并不是一个答案——我希望这两个宏都能像正常的Ant任务一样独立运行,用户不必知道它们是宏。)谢谢,但这不是我想要的。
jar doesn't support the nested "defaultfs" element.
<macrodef name="jc">
    <attribute name="name" />
    <attribute name="destdir" />
    <attribute name="fileset.path.to.consider" />
    <sequential>
        <jar destfile="@{destdir}${file.separator}@{name}.jar" update="false">
            <defaultfs path="@{fileset.path.to.consider}"/>
            <manifest>
                <attribute name="Manifest-Version" value="1.0" />
            </manifest>
        </jar>
    </sequential>
</macrodef>
<jc destdir="${dir.build.jar}" name="thejar" fileset.path.to.consider="org/path/inner"/>