This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma 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 Java Interview Guide this week in the Jobs Discussion 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

STEP-BY-STEP creating a WAR file

Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2373

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.
+ WEB-INF/ ---->|
web.xml+classes --->|
--all gif files

--Other jsp files
--Other html files

Then compile under wrTag package as STEP-2. Copy the compiled file according to chart-1. Source Code for 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" %>
<title>Testing Custom Actions</title>
<body bgcolor= #D5F6C7 background="/wrTag/WEB-INF/images/rolleyes.gif" text=blue>
This is a static content called template text!
<p />
This is a static content again!

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"
<description>Custom Tag Extension Example</description>
<!-- Tag Library Descriptor by Ashik-->
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.
Chintan Rajyaguru
Ranch Hand

Joined: Aug 19, 2001
Posts: 341
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 - 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.
- satya

Take a Minute, Donate an Hour, Change a Life
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2373

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"
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> Display JSP sources </description>
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?
Ashik Uzzaman
Ranch Hand

Joined: Jul 05, 2001
Posts: 2373

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

Joined: Feb 05, 2001
Posts: 17276

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

Perfect World Programming, LLC - iOS Apps
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:
subject: STEP-BY-STEP creating a WAR file
It's not a secret anymore!