Hi,
This is using the FreeMarker 2.3.15 Maven distribution.
My apologies if this question has been asked before; I've created a
custom tag library and packaged it as a standard Maven JAR. The actual
tag library descriptor (.tld) is located under
<jar_root>/META-INF/my-tags.tld, and it declares the URI "/my-tags".
This way, I can just add a dependency on it to my web application (which
also uses Maven) and get the JAR placed in the /WEB-INF/lib dir. I
believe it is since JSP 2.0 that any .tlds in /META-INF get
automatically discovered, and that you can use them as long as you use
the same URI in your JSP as is declared in the .tld. All this works, I
can use the taglib without having to explicitly declare it in web.xml.
The problem now is that I need to use my JSP tag library in some
FreeMarker templates within Struts 2, so I'm trying to do:
<#assign my=JspTaglibs["/my-tags"]>
This fails. I'm getting the following error dumped all over my output in
a yellow-and-red box:
Could not find webapp resource /my-tags
The problematic instruction:
----------
==> assignment: my=JspTaglibs["/my-tags"] [on line 1, column 1 in
WEB-INF/themes/medicmind/columnize.ftl]
----------
Java backtrace for programmers:
----------
freemarker.template.TemplateModelException: Could not find webapp
resource /my-tags
at freemarker.ext.jsp.TaglibFactory.loadTaglib(TaglibFactory.java:432)
at freemarker.ext.jsp.TaglibFactory.access$300(TaglibFactory.java:106)
at freemarker.ext.jsp.TaglibFactory$Taglib.load(TaglibFactory.java:414)
at freemarker.ext.jsp.TaglibFactory.get(TaglibFactory.java:158)
at
freemarker.core.DynamicKeyName.dealWithStringKey(DynamicKeyName.java:136)
at
freemarker.core.DynamicKeyName._getAsTemplateModel(DynamicKeyName.java:94)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
I've actually done this before and it worked that time, but the tag
library was packaged within the web application itself, so I could use a
direct path to /WEB-INF for JspTaglibs. I've now moved the tags and
their tag library in their own separate JAR and am trying to have it
load from there.
Apparently the JspTaglibs directive is handled by the TaglibFactory
class; after examining the source for it I found that it would probably
work to do something like:
<#assign
my=JspTaglibs["/WEB-INF/lib/my-tags-0.1.jar:/META-INF/my-tags.tld"]>
But this doesn't either. Regardless, I would really want to avoid
hardcoding the library version number in there.
Upon further examination of TaglibFactory.java, I've found that it is
capable of scanning all JARs in /WEB-INF/lib and discovering the TLDs in
it (method getLocationsFromLibJars). Following the code path in my head,
this would definitely discover my TLD and solve the problem of
hardcoding JAR names along the way. The only problem is that
getLocationsFromLibJars never gets a chance to run because of the way
this loop is constructed (method get(String uri)):
do {
if(taglib.load(uri, ctx, locations)) {
taglibs.put(uri, taglib);
return taglib;
}
}
while(getMoreTaglibLocations());
taglib.load basically wraps some housekeeping around static loadTaglib,
which seems to be responsible for trying to load the taglib as a
resource within the servlet context (ie. from somewhere within /WEB-INF
or the web app root). The problem is that if it loadTaglib can't find
that resource, it throws an exception which bubbles all the way up so
that getMoreTaglibLocations doesn't get a chance to get called.
Was this behaviour intended? Is there any configuration I'm missing? Is
there any way to do this?
Thanks in advance,
Jeroen DR
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.
http://p.sf.net/sfu/bobj-july_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel