Thursday, December 19, 2013

DIFFERENCE BETWEEN JAR, WAR AND EAR FILES

what is a jar? – java Application archive

A Jar file is an archive of many java class files and its associated metadata and resources. The resources can be text, images, html and so on. The JAR format is useful when trying to download a java application in a single click compared to downloading each resource by its name.

A JAR file can have a manifest file. A manifest file can contain paths to other JARs that need to be in place for the JAR to work properly.

The diagram below shows a hypothetical structure


An enterprise application can have multiple tiers. In JEE world, the tiers can be client, web, app and EIS.

A Java enterprise application is deployed on containers. These containers are of two types :
Web Container ex: Tomcat, Jetty
EJB container. ex: Weblogic

A web container hosts JSP/Servlet API which are more or less a request/response handling. The Web container cannot host EJBs which are based on EJB API. The EJB API provides transaction declaration, method level security etc.

A web container has a web.xml in WEB-INF folder. An EJB container has ejb-jar.xml under META-INF folder. These xmls are called descriptors. These descriptors define the structure of the application. A web-inf does it for a web application and an ejb-jar does it for bean implementation.

A java application thus can be archived to be a -
simple JAR file for local use
A WAR file which can have jar files in it to be hosted on a web container
An EAR file which can have both WAR and JAR inside it to and hosted on a JEE container which support EJB