O'Reilly logo

Java Servlet & JSP Cookbook by Bruce W. Perry

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

22.5. Packaging the Tag Library in a JAR File

Problem

You want to make your tag library available in a JAR file.

Solution

Create a JAR file that contains your tag handler class or classes in the correct directory structure (with subdirectory names matching the package names). Place the tag library descriptor file in the JAR's META-INF directory. Then put the JAR in the WEB-INF/lib directory of your web application.

Discussion

To make your tag library portable, store all of your tag handler classes and tag files in a JAR file.

Tip

In a JAR, store any tag files in META-INF/tags or a subdirectory of META-INF/tags. If you don't, the JSP container will not recognize them as legitimate tag files. See Recipe 22.11 for details.

You can generate this JAR file from a directory that contains your tag library classes, including their package-related subdirectories. For example, the logo tag I developed in this chapter has a package name of com.jspservletcookbook, so the relative path to this file is com/jspservletcookbook/LogoTag.class. Include a META-INF directory at the top level of the directory where the classes are stored (e.g., in the same directory as the one containing com). Place your tag library descriptor file in the META-INF directory or a META-INF subdirectory.

If your library includes any tag files, place them in META-INF/tags or a subdirectory of META-INF/tags. Change to the directory containing all these subdirectories and type the following command line, substituting your own JAR ...

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