How-to: Package JSP custom taglibs in JAR

Just recently I discovered a simple problem in our application around the packaging of custom taglibs in JARs. Looking into the issue, it seems that the ".tld" files were placed in the /WEB-INF/tld folder in the JAR! That is wrong. The correct way to do it is…

source: JSP 1.2 Specification (see references below)

JSP.7.3.1 Identifying Tag Library Descriptors

Tag library descriptor files have names that use the extension ".tld", and the extension indicates a tag library descriptor file. When deployed inside a JAR file, the tag library descriptor files must be in the META-INF directory, or a subdirectory of it. When deployed directly into a web application, the tag library descriptor files must always be in the WEB-INF directory, or some subdirectory of it.

Articles listed in the References (see below) discuss the details of specifying uri in taglib descriptor and referring taglibs using absolute URI without the need to create aliases in web.xml. Eventhough this feature is couple of years old, there still seem to be some issues around the support of this feature by some servlet containers. But as far as I know it works with WebSphere and Tomcat.

If you are wondering what good these absolute URI’s do, refer to the JSP 1.2 Spec for more details. It pays to read the specs once in a while!

References

  1. JSP best practices: Pack ’em up!
  2. Dry your taglib URIs
  3. If you are planning to build a new custom tag library, take a look at Jakrata Taglibs. May be you will find something useful. If you like them, continue on to Jakarta Taglibs Tutorial
  4. JSR 53: JavaTM Servlet 2.3 and JavaServer PagesTM 1.2 Specifications
  5. JSR 154: JavaTM Servlet 2.4 Specification
  6. JavaServer Pages Standard Tag Library
  7. JSR 52: A Standard Tag Library for JavaServer PagesTM
The following two tabs change content below.
Content Team

Content Team

The IndicThreads Content Team posts news about the latest and greatest in software development as well as content from IndicThreads' conferences and events. Track us social media @IndicThreads. Stay tuned!
Content Team

Content Team

The IndicThreads Content Team posts news about the latest and greatest in software development as well as content from IndicThreads' conferences and events. Track us social media @IndicThreads. Stay tuned!

  • Noname

    who sain anything about php?

  • Guest

    😕 so whuts the big idea creating the iste in PHP????…..isnt this a J2EE site, so IMHO shudnt the site be in JSP or sumthing? 😕

  • Guest

    the reason why i think these tlds appear in the wrong place is that developers develop the app by placing the tlds in a ‘tld’ folder in WEB-INF and when done just pack the app as a JAR without realizing that hey need to change the location of the tld file.
    With JSP 2.0 the server is able to find tld files in any folder within WEB-INF so WEB-INF/tld works fine if it is not as a jar file.