Re: TLD files packaged in JAR required to be under META-INF/resources?

Jeremy Boynes <[email protected]> Wed, 30 May 2018 08:59:48 -0700
Newsgroups gmane.comp.jakarta.taglibs.user
Message-ID <[email protected]>
> On May 30, 2018, at 3:13 AM, Tomas Hofman <[email protected]> wrote:
>=20
> Hello,
>=20
> I run into something that looks like non spec-conforming behavior and =
would like to check with you if it's really a bug or I'm having =
incorrect expectations.
>=20
> I have TLD located in JAR under META-INF/tlds/hi.tld. The JAR also =
contains web-fragment.xml with taglib mapping like this:
>=20
>  <web-fragment ...>
>    <jsp-config>
>        <taglib>
>            <taglib-uri>/HiTag</taglib-uri>
>            <taglib-location>/tlds/hi.tld</taglib-location>
>        </taglib>
>    </jsp-config>
>  </web-fragment>
>=20
> This JAR is loaded in a WAR, that contains JSP with following =
directive:
>=20
>  <%@ taglib uri=3D"/HiTag" prefix=3D"say"%>
>=20
> During deployment in apache-tomcat-9.0.8 I see this warning:
>=20
> 30-May-2018 10:38:42.240 WARNING =
[ContainerBackgroundProcessor[StandardEngine[Catalina]]] =
org.apache.jasper.servlet.TldScanner.scanJspConfig Failed to process TLD =
with path [/tlds/hi.tld] and URI [/HiTag]. The specified path does not =
exist.
>=20
> and the jsp compilation fails.
>=20
> When I move the TLD under META-INF/resources, then it starts to work.
> When I use implicit mapping by defining <uri> element in hi.tld =
instead of explicit mapping in web-fragment.xml, that works too.
>=20
> The JSP spec says that TLDs must be in META-INF/ or subdirectories:
>=20
> [quote]
> JSP 7.3.1
>=20
> When deployed inside a JAR file, the tag library descriptor files must =
be in the META-INF directory, or a subdirectory of it.
> [/quote]
>=20
> I think it's caused by this line in TldScanner.java:
>=20
> =
https://github.com/apache/tomcat/blob/TOMCAT_8_0_0_RC10/java/org/apache/ja=
sper/servlet/TldScanner.java#L177
>=20
> where ServletContext#getResource() would naturally see only files =
under META-INF/resources/ dir.
>=20
> Thanks for any opinions!

This may be better addressed to [email protected] as this really relates to the =
Jasper JSP engine rather than the taglib itself. Having said that, =
here=E2=80=99s how I read the spec.

JSP 7.3.3 talks about a =E2=80=9Ctaglib map=E2=80=9D using elements in =
the deployment descriptor per your example. Per JSP 7.3.2 the URI is =
mapped to a _context relative path_ interpreted relative to the root of =
the web application. Resources contained in a web fragment jar are =
located in its /META-INF/resources directory. Tomcat/Jasper are =
synthesizing the effective web application from the resources in the =
fragments, then resolving the URI in the taglib map against that merged =
application. I think that=E2=80=99s a correct interpretation of the =
spec.

JSP 7.3.1 refers to implicit map entries found by scanning the web =
application=E2=80=99s jars from WEB-INF/lib

--
Jeremy