1
我想從另一個宏的元素中調用宏。 讓我們假設我有以下宏:螞蟻嵌套宏調用
<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>
和另一個宏
<macrodef name="defaultfs" description="Defines the default fileset">
<attribute name="path" />
<sequential>
<fileset dir="${dir.build.classes}">
<include name="@{path}/**/*.class" />
</fileset>
<fileset dir="${src.ehs}">
<include name="@{path}/**/icons/**" />
<include name="@{path}/**/sounds/**" />
<include name="@{path}/**/*.gif" />
<include name="@{path}/**/*.png" />
<include name="@{path}/**/*.wav" />
<include name="@{path}/**/*.jpg" />
<include name="@{path}/**/*.properties" />
<include name="@{path}/**/*.xml" />
<include name="@{path}/**/jaxb.index" />
</fileset>
</sequential>
</macrodef>
我使用這些宏如下:
<jc destdir="${dir.build.jar}" name="thejar">
<fileset-list>
<defaultfs path="org/path/inner" />
</fileset-list>
</jc>
我得到的是以下錯誤消息:
jar doesn't support the nested "defaultfs" element.
什麼是錯的?
未將「jar」ANT任務編寫爲支持「defaultfs」XML元素。 ANT中的宏有些不同,它們更像模板。 – 2014-12-02 21:05:57
你是對的,但我的要求是以更廣泛的方式使用jc,並且我有一些使用類似文件集構建的jar。 宏是否只評估一次? – landal79 2014-12-03 10:03:48
我有一個類似的情況,我想在一個宏(隱式)元素參數中使用宏。還沒有想出如何 - 或者如果可能的話 - 在外部宏之前獲得內部宏評估。如果你能找到答案,我絕對有興趣! (不,結合這兩個宏並不是一個答案 - 我希望其中的每一個獨立行動,就像它是一個普通的Ant任務一樣,用戶不必意識到它們是宏。) – keshlam 2015-03-17 12:44:23