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
- JSP best practices: Pack ’em up!
- Dry your taglib URIs
- 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
- JSR 53: JavaTM Servlet 2.3 and JavaServer PagesTM 1.2 Specifications
- JSR 154: JavaTM Servlet 2.4 Specification
- JavaServer Pages Standard Tag Library
- JSR 52: A Standard Tag Library for JavaServer PagesTM
who sain anything about php?
😕 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? 😕
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.