This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes STEP-BY-STEP creating a WAR file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "STEP-BY-STEP creating a WAR file" Watch "STEP-BY-STEP creating a WAR file" New topic
Author

STEP-BY-STEP creating a WAR file

Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

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 Member of Technical Staff, Salesforce.com, San Francisco, CA, USA.
Chintan Rajyaguru
Ranch Hand

Joined: Aug 19, 2001
Posts: 341
Ashik,
Thanks for sharing this information. Someone at work was asking me questions related to this. Now, I will ask him to visit your post.
Chintan


ChintanRajyaguru.com
SOADevelopment.com - Coming soon!
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1242
thanks Ashik uzzaman ! great work!
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Good job, Ashik.
Thanks.
- satya


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

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>
faiza haris
Ranch Hand

Joined: Oct 17, 2000
Posts: 173
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
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2370

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....
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Oh sure put the TLD in after I printed this post.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Can't you be a little lazy....
Why are you always in such a hurry, huh?
- satya
faiza haris
Ranch Hand

Joined: Oct 17, 2000
Posts: 173
Thanx for the reply Ashik!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: STEP-BY-STEP creating a WAR file
 
Similar Threads
about taglib-uri
Invalid web JAR
Error Displaying Custom Tags in JSp
writing jsp codes
Error When starting Tomcat server