O'Reilly logo

JavaServer Pages, Second Edition by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Packaging and Installing a Tag Library

There are basically two ways the files that make up a tag library (the TLD and all the class files) can be made available to a container: packaged in a JAR file or kept as regular files in the filesystem. On top of this, there are three ways to identify the tag library you use in a JSP page. Let’s look at the two topics one at a time.

Making the Tag Library Files Available to the Container

During development, you may want to let the tag library classes and the TLD file reside as-is in the filesystem, since it makes it easy to change the TLD and modify and recompile the classes. Just make sure the class files are stored in a directory that’s part of the classpath for the JSP container, such as the WEB-INF/classes directory for the web application. The TLD must be also available as a file with a .tld extension in a directory where the JSP container can find it. The recommended location is the WEB-INF/tlds directory.

When you’re done with the development, you may want to package all tag-handler classes and the TLD in a JAR file. This makes it easier to install the library in an application. In this case, the TLD must be placed as a file with a .tld extension in the META-INF directory in the JAR file, for instance as META-INF/taglib.tld.

To create the JAR file, first arrange the files in a directory with a structure like this:

META-INF/
  taglib.tld
com/
  ora/
    jsp/
      tags/
        ForwardTag.class
        ...
      util/
        StringFormat.class
        ...

The structure for the class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required