File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Deploying servlet in tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Deploying servlet in tomcat" Watch "Deploying servlet in tomcat" New topic

Deploying servlet in tomcat

Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
hi friends,

I am working on servlets and using tomcat as my server. After writing the servlet, i am updating the deployment descriptor file (web.xml).

Servlet is running smoothly.
why do i need to create WAR file ?
What is EAR file ?
How to create them in tomcat ?
what is Jar file?

Clarify me....

Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
warfiles aren't strictly necessary to deploy web applications, they just make it easier.
earfiles are for applications that include more than a web component (usually EJBs).
jarfiles are just prepackaged components that belong together.

Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
If everything works well, then why do we need WAR files...
In which conditions should we develop WAR files and how in webservers like tomcat?
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Usually you will use a war file when your application become large, and it is easier to package it into one file. It makes it easier to deploy and send to others. Kind of like using a zip. If you have many files and you want to email them to a friend, don't you zip up all the files and just send them the zip file?


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
Thank u for ur explanation.

Can u let me know how to create WAR file in tomcat ?
IS the application uses WAR file ?
Nandini Sriram
Ranch Hand

Joined: Jul 04, 2003
Posts: 132
Hi Priya,

WAR is WebArchive.
EAR is EnterpriseArchive.
You can create a WAR like this:
>jar cvf myApp.war WEB-INF {related top-level files or directories}.
I think this link would be helpful.
Creating a simple WAR file


Discipline, Dedication and Determination define Destiny.
Senthil B Kumar
Ranch Hand

Joined: Feb 09, 2004
Posts: 160
all the 'R' files (waR,eaR,jaR) are just an ordinary compressed (zipped) java Classfiles (and if needed
other kind of files also). Then what is the speciality in them ? It makes the distribution of the
application easier.

ie. you have written an web application, with 100's of JSP's and numerous Servlets, then what would
you do if your client wants your web application. You would zip/compress the root folder and send it. and
ask the client to unzip it and use it. But with these 'R' files, you just send this single file and user will
deploy them in the Server. They will not worry what to do with this archive file, they will just deploy.

This deploying task will differ from Server to Server, it may be a way in BEA WLS,another way in TOMCAT
.. and like that.

if you have only Web Components in your application (ie JSP's,Servlets and other static files like image,
..etc) you make a WAR out of them.

if you have only JAVA (EJB's or Ordinary Java files , not Servlets) Components in your application
you make a JAR out of them.

if your application has both Web Components and Java Components, you make a WAR out of
web components,make a JAR out of java components and finally make an EAR out of your JAR & WAR.

as a Rule of Thumb, each of the 'R' files ,will have a Descriptor file in it, which tells the Server
what to do, when deployed.

WAR should have Web Descpritor web.xml
JAR should have EJB Descriptor ejb-jar.xml
EAR should have Application Descriptor application.xml

Creation of these 'R' files are not Server specific. Same war/jar/ear file can be deployed in any Server
(if the jar contains EJB then its an exception, it cant be just like that deployed in any Server)

Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
Currently I Reside Here WEBlog
I agree. Here's the link:
subject: Deploying servlet in tomcat
jQuery in Action, 3rd edition