Where to place the TLD / taglib files inside the WAR

Solution Verified - Updated

Environment

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

Issue

  • JBoss can not find tld file in application war file.
org.apache.jasper.JasperException: File "/WEB-INF/lib/TEST-taglib.tld" not found
	org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51)
	org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
	org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:116)
	org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:177)
	org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:386)
	org.apache.jasper.compiler.Parser.parseDirective(Parser.java:448)
	org.apache.jasper.compiler.Parser.parseElements(Parser.java:1398)
	org.apache.jasper.compiler.Parser.parse(Parser.java:130)
	org.apache.jasper.compiler.ParserController.doParse(ParserController.java:255)
	org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
	org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:194)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:360)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:328)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:607)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:312)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:328)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
  • The same application works fine in "Weblogic 10.3.0", However it causes the above exception while migrating from "Weblogic 10.3.0" to JBoss.

  • It is verified that the tld file (TEST-taglib.tld) is in the "WEB-INF/lib" directory and the classes that it references are also contained within the same war file.

  • Is it possible to load the tlds inside the jar META-INF directory from a JBoss custom module ?

  • Getting an issue in EAP 6.2.0 as org.apache.jasper.JasperException: JBWEB004036: File "/WEB-INF/lib/mytag.tld" not found.

  • We have web application developed in Struts 2 ,previously it was on Jboss 5.1.0,at that time its working fine,recently we moved to Jboss 6.2,but now it gives mytag.tld not found error.

org.apache.jasper.JasperException: JBWEB004036: File "/WEB-INF/lib/mytag.tld" not found
  • TLD not getting loaded from jar file in war with this error:
org.apache.jasper.JasperException: JBWEB004113: The absolute uri: http://www.jboss.org/examples/tags-form cannot be resolved in either web.xml or the jar files deployed with this application

Resolution

JSP 2.0 Specification Section Snippet:

  • JSP.7.3.4 Implicit Map Entries from TLDs
    • The taglib map described in web.xml is extended with new entries extracted from TLD files in the Web Application. The new entries are computed as follows:
    • The container searches for all files with a .tld extension under "/WEB-INF" or a subdirectory, and inside JAR files that are in "/WEB-INF/lib". When examining a JAR file, only resources under "/META-INF" or a subdirectory are considered. The order in which these files are searched for is implementation-specific and should not be relied on by web applications.

JavaServer Pages 2.2 Specification

Content from download.oracle.com is not included.Content from download.oracle.com is not included.http://download.oracle.com/otndocs/jcp/jsp-2.2-mrel-oth-JSpec/

  • JSP.8.4.1 Location of Tag Files
    • Tag extensions written in JSP using tag files can be placed in one of two locations.
      • The first possibility is in the /META-INF/tags/ directory (or a subdirectory of /META-INF/tags/) in a JAR file installed in the /WEB-INF/lib/ directory of the web application. Tags placed here are typically part of a reusable library of tags that can be easily dropped into any web application.
      • The second possibility is in the /WEB-INF/tags/ directory (or a subdirectory of /WEB-INF/tags/) of the web application. Tags placed here are within easy reach and require little packaging. Only files with a .tag or .tagx extension are recognized by the container to be tag files.
    • Tag files that appear in any other location are not considered tag extensions and must be ignored by the JSP container. For example, a tag file that appears in the root of a web application would be treated as content to be served.

NOTE: It is not checking the classpath for the TLDs, it expects it to be in the war.

See: JSP.7.3.2 TLD resource path

  • The following order of precedence applies (from highest to lowest) when building the taglib map (see the following sections for details):
    • If the container is Java EE platform compliant, the Map Entries for the tag libraries that are part of the Java EE platform. This currently includes the JavaServer Pages standard Tag Library libraries and the JavaServer Faces libraries.
    • Taglib Map in web.xml
    • Implicit Map Entries from TLDs
      • TLDs in JAR files in WEB-INF/lib
      • TLDs under WEB-INF
    • Implicit Map Entries from the Container

EAP 6.4


Loading TLD files out of modules is supported on EAP 6.4. See **Load taglibs from jars in a JBoss Module** in the ["New Features" section of the EAP 6.4 release notes](https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.4/html-single/6.4.0_Release_Notes/index.html#New_Features)

Notes

There was a regression found and fixed:

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.