Hi ranchers, As i faced many problems understanding & deploying Web Archive Files the last few days, here i m providing the step-by-step simple instructions of how to create a WAR file under Tomcat4.0.1+Windows 2000 server for all your benefits. A web archive is a jar file that contains a whole web application structure including html,gif,jsp,servlet,javabean,jar etc various files. I created a context ashik4u in my root directory of tomcat. Placed various jsp,html,fiels there. You may create this under a directory of your name as STEP-1. I'll refer the follwing figure as chart-1. ashik4u ======= | + META-INF/ MANIFEST.MF | + WEB-INF/ ---->| web.xml+classes --->| +wrTag/ HelloTag.class | +tlds hello.tld | +images --all gif files
CustomAction.jsp --Other jsp files design.html --Other html files
Then compile HelloTag.java under wrTag package as STEP-2. Copy the compiled file according to chart-1. Source Code for HelloTag.java is taken & modified from Professional Java Server Programming Volume I :
As STEP-3, Write down the tag library descriptor file & save according to chart-1. As STEP-4, write down a simple JSP file named CustomAction.jsp like the follwoing and save it as chart-1. <%@ taglib uri="/customAction" prefix="myExample" %> <html> <head> <title>Testing Custom Actions</title> </head> <body bgcolor= #D5F6C7 background="/wrTag/WEB-INF/images/rolleyes.gif" text=blue> This is a static content called template text! <p /> <i> <myExample:customAction></myExample:customAction> </i> This is a static content again! </body> </html>
Now STEP-5 would be to write down a deployment descriptor (web.xml file) for your web application. I assume u r not using Tomcat3 and rather Tomcat4. Otherwise you have to edit a little the code for web.xml that follows to be saved according to chart-1 --- ==================================================================== <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>wrTag</display-name> <description>Custom Tag Extension Example</description> <session-config> <session-timeout>0</session-timeout> </session-config> <!-- Tag Library Descriptor by Ashik--> <taglib> <taglib-uri>/customAction</taglib-uri> <taglib-location>/WEB-INF/tlds/hello.tld</taglib-location> </taglib> </web-app> ===================================================================== Write down a manifest file named MANIFEST.MF under META-INF. But i m still whether this manifest file must have the entry for the HellTag class or not. The code goes --- Manifest_Version: 1.0 Name: ..\CustomAction.jsp Name: ..\WEB-INF\tlds\hello.tld Name: ..\WEB-INF\web.xml Name: ..\WEB-INF\classes\wrTag\HelloTag.class
Now STEP-7 would be make a war file thru jar command going to ashik4u directory in DOS prompt. The command is : jar -cvf custom.war META-INF/MANIFEST.MF WEB-INF/classes/wrTag/HelloTag.class WEB-INF/images/*.gif *.html *.jsp At this stage you'll find a war file named custom.war which we desired so much. As STEP-8 copy this file to the lib directory of your tomcat installation directory. STEP-9 is to restart Tomcat to recognize this new custom.war and its directory structure. If catalina reports error during startup, find out the error, edit in appropriate file and then repeat STEP-7 TO STEP-9. STEP-10 just accessing your newly created war in one of two ways : (A) Write down & hit in your browser "http:localhost:8080/wrTag/CustomAction.jsp" (B) Write down another html or jsp page and give the above addess as a href/html link to access.
That's all and now i m waiting for suggessions & comments from u. Any better and alternate ideas r most welcome! Without creating the war file i wanna know how can i access the custom tags in my jsp file.
Ashik Uzzaman Senior Software Engineer, TubeMogul, Emeryville, CA, USA.
Sorry that i forgot to provide the source code of tag library descriptor (tld file) at STEP-3. Here it goes.... <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd"> <taglib> <tlib-version>1.0</tlib-version> <jsp-version>1.2</jsp-version> <short-name>myExample</short-name> <uri>http://jakarta.apache.org/tomcat/example-taglib</uri> <description> A simple tag library for testing custom actions in JSP. It was "info" in earlier version. I m placing my custom tag handlers here --- Ashik. </description> <tag> <name>customAction</name> <tag-class>wrTag.HelloTag</tag-class> <body-content>JSP</body-content> <description> Display JSP sources </description> </tag> </taglib>
Thank you Ashik!! i am studying tags and this is really handy! what sequence is best for the understanding of tags...i am following Core Servlets and jsp and then jsp spec and then J2ee tutorial? is that enuf? thanx
Faiza, sorry to be late to reply. I think u should think of some code that'll be used by custom tags in ur JSP with empty, JSP & tagdependent body-content for completeness. And when following Core Servlets & JSP u should keep eyes on deprecations and More Servlets & JSP also....