从 Apache Ant 宏中访问 Antlib 资源 [英] Access Antlib Resources From Within Apache Ant Macros

查看:25
本文介绍了从 Apache Ant 宏中访问 Antlib 资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从 Antlib 中定义的 Apache Ant 宏中访问资源?

Is it possible to access resources from within Apache Ant macros defined in an Antlib?

例如,在我的 antlib.xml 中,我有一个执行 XSLT 的宏.理想情况下,我希望将 XSLT 文件与 antlib.xml 打包在同一个 JAR 中,但我不知道如何指定 XSLT 的位置.

For instance, within my antlib.xml, I have a macro that performs some XSLT. Ideally I would like the XSLT file to be packaged in the same JAR as the antlib.xml, but I have no idea how to specify the location of the XSLT.

这是(简化的)代码:

<antlib xmlns:tibant="antlib:org.windyroad.tibant">
    <macrodef name="configure-ear">
        <attribute name="xml" />
        <attribute name="out" />
        <sequential>
            <xslt in="@{xml}"
                  out="@{out}"
                  style="...what to put here...">
            </xslt>
        </sequential>
    </macrodef>
</antlib>

问题是,我在 style 属性中放置的任何内容都与使用 antlib 的项目的 basedir 相关,我找不到任何方法来指定相对于 antlib.xml 的路径.

The problem is that whatever I put in the style attribute is relative to the basedir for the project using the antlib and I can't find any way to specify a path relative to the antlib.xml.

有什么想法吗?

我可以将 XSLT 作为一个单独的文件发送,但是我需要给用户一些方法来指定 XSLT 的位置,这并不理想(例如设置 tibant.home 属性).我还可以使用 echoxml 将 XSLT 写出到临时文件,但 IMO 是一种黑客行为.

I can ship the XSLT as a separate file, but then I would need to give users some way to specify the location of the XSLT, which is not ideal (e.g. setting a tibant.home property). I could also use echoxml to write out the XSLT to a temp file, but IMO that's a hack.

推荐答案

不要使用 style 属性,而是尝试使用嵌套的