|
<taglib:tutorial lesson="packaging"/>
This part of the tutorial goes through the procedure of packaging archives with Suns JAR utility.
1 Packagning
This part of the tutorial goes through the procedure of packaging archives with Suns JAR utility.
It is strongly suggested that you use an IDE when developing Java applications. Most IDEs has JAR utilities that are simple and reliable.
2 Packaging a Taglib
Throughout the tutorial we use unpackaged Taglibs. In real life, you would like to package your Taglibs so that they are easy to distribute and keep track on.
A packaged Taglib consists of the needed classes (and resources such as property bundles) and a Taglib descriptor. The Taglib descriptor should be located in a subdirectory called 'META-INF'.
-
Create a new temporary directory called 'taglib' in a directory of your choice.
-
Create a subdirecty to the 'taglib' directory called 'META-INF'.
-
Copy your taglib.tld file into the 'META-INF' directory.
-
Copy all your class files (and their package space) to the 'taglib' directory.
Your file structure should now look something like the following:
 Figure 1: A typical Tag Library structure.
-
Start up a command shell.
-
Place yourself in the 'taglib' directory and issue the following command.
Listing 1: Sample JAR-tool command
This will create a JAR named 'taglib.jar' containing all files in the current directory and in any subdirectories.
Inside a web-application, your packaged Taglib should be located in the '/WEB-INF/lib/' directory.
A reference to a packaged Taglib from a web.xml file should look something like the following:
<taglib> <taglib-uri>acmetags</taglib-uri> <taglib-location>/WEB-INF/lib/taglib.jar</taglib-location> </taglib>
|
Listing 2: Sample Taglib reference in the web.xml descriptor.
Notice that with a packaged Taglib we point to the JAR file itself, and the container will know where to find the Taglibs descriptor. When we have a unpacked Taglib, we point out the descriptor of the Taglib. Of course, the same goes for JSP pages referencing Taglibs directly.
Copyright ©
2005 IronFlare AB
|