从 Apache Ant 宏中访问 Antlib 资源 [英] Access Antlib Resources From Within Apache Ant Macros
问题描述
是否可以从 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
属性,而是尝试使用嵌套的 元素,这将允许您指定
javaresource
作为样式床单.然后,您可以将样式表放在 jar 中的 antlib.xml 旁边,它将在类路径中可用.
Instead of using the style
attribute, try a nested <style>
element, which will allow you to specify a javaresource
as the style sheet. You can then put the stylesheet next to your antlib.xml in the jar, and it will be available on the classpath.
<xslt in="@{xml}"
out="@{out}">
<style>
<javaresource name="your/package/structure/style.xslt" />
</style>
</xslt>
这篇关于从 Apache Ant 宏中访问 Antlib 资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!