访问的antlib资源从在Apache Ant的宏 [英] 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文件被打包在同一JAR的 antlib.xml
,但我不知道如何指定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.
下面是(简体)code:
Here is the (simplified) code:
<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>
问题是,无论我放在风格
属性是相对于 BASEDIR
项目使用的antlib,我无法找到任何方式指定相对于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到一个临时文件,但国际海事组织这是一个黑客。
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.
推荐答案
风格属性,尝试嵌套&LT;风格&GT;
元素,这将允许您指定 javaresource
的样式表。然后,你可以把样式表旁边的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>
这篇关于访问的antlib资源从在Apache Ant的宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!