TomcatExpert

Best practice for implementing custom tag libraries

posted by SpringSource on October 27, 2009 03:20 PM

Correctly placing and referencing TLD libraries

Tomcat 5.5 documentation indicates that JAR files containing libraries should be stored in the webapps META-INF directory, per the JSP specification:

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. The DTD for a TLD document is "http://java.sun.com/dtd/webjsptaglibrary_ 1_2.dtd"

The same requirement is also hinted in the newer Tomcat API documentation:

If the web application expects to load the library as a file, not from the classpath, the TLDs would not be loaded even if is in the classpath.

Tomcat will not autodeploy the TLD libraries that are referenced by JAR files even the TLD libraries are in the classpath. The TLD libraries have to be correctly placed, or referenced by the web application's web.xml where they can be found and loaded using the ServletContext.getResource() call.

For more than 10 years, SpringSource employees have been supporting Apache technologies, with unparalleled experience and commitment to the Apache Software Foundation. More than 400 of the Fortune 500 count on SpringSource to support their mission-critical business applications. Leaders of the Apache Software Foundation, including Board Members, work at SpringSource and dedicate a significant amount of time further developing the Apache Tomcat open source project. Over the last 2 years, 95% of the issues fixed in the Apache Tomcat project were fixed by SpringSource engineers. For more information on how SpringSource can help your enterprise, see the SpringSource website, or call 800/444-1935.

Comments

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.