• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

confused between jar and war files

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have looked through HeadFirst Servlets + JSP book ed2 and am stuggling to work out the difference between jar files and war files and where they can be located in a web application.
I have a few questions about comparisions that i am struggling with.

Q1. From what i read, they are the same thing - jar and war files. You can rename a war file to a jar file and it will work without having to move any files. And the same with a jar file, you can rename it to a war file and everything will work fine.

Q2. But if they are the same thing, does that mean they are stored in the same places too? Because from what i can see, they are not:

Q3. I have read that you put war files under /webapp folder AND nowhere else. And that ear war file is considered as a separate web application - correct?

Q4. It appears that you put jar files under /webapp/WEB-INF/lib and nowhere else. Is that correct?


I didnt find much info on this area in the HeadFirst Servlets + JSP book ed2.

Thanks in advance for clearing these concerns up for me :-)
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't studied this part yet, so I will post what I have learned from working with Java and web apps, ok?

Q1 - jar files and war files mean different things, you really can rename a jar into a war and a war into a jar but they probably won't work.
You can say they are the same because the algorithm used to generate this files are the same (creating a jar is kind of zipping a folder) what changes is just the extension, but a war file represents a whole webapp, which means that the files inside a war file obeys the same structure as your application folder inside tomcat for example. A jar file may represent a set of components and classes, like servlet-api.jar, you have got the whole servlet api in it and it's not an application.

Q2 and Q3 - If you put a war file inside tomcat's webapp folder, tomcat will treat it as a webapp and will try to start it (look for a WEB-INF folder, read the web.xml file, create a context, map the servlets, listeners and so on).
You will put jar files into WEB-INF/lib when this jars are used by your web application, like a custom jar with your set of classes, frameworks jar like log4j, hibernate or spring from example.
EARs files are used when you have more than one application (2 war files for exemple) and they need to share resources like jar files, property files or anything else so you don't need to duplicate this resources. EARs are sometimes used to keep things organized too.

Q4 - putting jar into WEB-INF/lib means that your webapp depends on this jars to work and that they are specifically to your webapp. The jars inside WEB-INF/lib will be in your webapp classpath when you deploy it, so when you generate a war file everithing inside the WEB-INF/lib will be packaged together.

hope this info helps and please post again if you didn't understand something.
 
reply
    Bookmark Topic Watch Topic
  • New Topic