TLDs under META-INF/resources inside the web-fragment jar are not loaded in JBoss EAP 7.x

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 7.x

Issue

TLDs under META-INF/resources inside the web-fragment jar are not loaded in JBoss EAP 7.x.

  • An example directory structure of the web-fragment jar
taglib-jar
|-- META-INF
|   |-- resources
|   |   `-- WEB-INF
|   |       `-- tlds
|   |           `-- example.tld
|   `-- web-fragment.xml
`-- simple
    `-- ExampleTag.class
  • web-fragment.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-fragment id="WebFragment_ID"
    version="3.0"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">
    ...(snip)...
 
    <jsp-config>
        <taglib>
            <taglib-uri>/ExampleTag</taglib-uri>
            <taglib-location>/WEB-INF/tlds/example.tld</taglib-location>
        </taglib>
    </jsp-config>
 
</web-fragment>

The following ERROR is thrown at the deployment:

ERROR [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0074: Could not find TLD /WEB-INF/tlds/example.tld

JSP returns "500 Internal Server Error" and Jastow throws the following ERROR when accessing the JSP which uses the taglib like <%@ taglib uri="/ExampleTag" prefix="say"%>:

ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /example.war/example.jsp: org.apache.jasper.JasperException: JBWEB004036: File "/ExampleTag" not found
	at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:57)
	at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:278)
	at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:75)
	at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:171)
	at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:412)
	at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:475)
	at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1459)
	at org.apache.jasper.compiler.Parser.parse(Parser.java:143)
	at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:223)
	at org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
	at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:200)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
	at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:652)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	...(snip)...

Resolution

This issue is reported as Content from issues.jboss.org is not included.JBEAP-14757 which will be fixed in JBoss EAP 7.1.4.

You can workaround this issue by specifying <taglib-location> with the real relative location of the tld in jar from the war root like /WEB-INF/lib/<jar-file-name.jar>/META-INF/resources/..:

<?xml version="1.0" encoding="UTF-8"?>
<web-fragment id="WebFragment_ID"
    version="3.0"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">

    <jsp-config>
        <taglib>
            <taglib-uri>/ExampleTag</taglib-uri>
            <!-- <taglib-location>/WEB-INF/tlds/example.tld</taglib-location> -->
            <taglib-location>/WEB-INF/lib/example-taglib.jar/META-INF/resources/WEB-INF/tlds/example.tld</taglib-location>
        </taglib>
    </jsp-config>

</web-fragment>

Or you can workaround this issue by using the deployment overlay feature to put the TLD as an overlay to the war:

deployment-overlay add --name=myTldOverlay --content=/WEB-INF/tlds/example.tld=/path/to/example.tld --deployments=example.war --redeploy-affected
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.