Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deploying servlet in tomcat

 
Priya Sri
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Then,
why do i need to create WAR file ?
What is EAR file ?
How to create them in tomcat ?
what is Jar file?

Clarify me....

bye
priya
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Mark
 
Priya Sri
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Regards,
Nandini
 
Senthil B Kumar
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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

p.s:
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic