Tuesday, June 10, 2008

JAR, WAR, and EAR - what are these files used for?

JAR - Java ARchive

It's a file format based on the ZIP file format and similar to ZIP format this is also used for aggregating many files (many be of different types) into one aggregate file. This aggregate file will have (.jar) extension. Application development using Java uses JAR files for many useful purposes. One of the most common use is to package all the .class files, image files, and other files required by an Applet into a JAR file, so that the download of a single file will have all the components downloaded at the client machine. Otherwise, we would require those many HTTP Connections to individually download each of the components and this will of course be a very tedious and time-consuming effort. Another popular usage is to bundle all the .class files, and other required component files of a typical subsystem into a JAR file and include that JAR file into the CLASSPATH of another Java application which requires the services of that subsystem. The maintenance and deployment becomes very easier in this case.

This archive file format is platform-independent format which has been fully written in Java. This format is capable of handling audio and image files in addition to the .class files. It's an open standard and fully extendable. JAR file consist of a ZIP archive and an optional Manifest file, which contains package and extension related data. The Manifest file will have the name 'MANIFEST.MF'. This manifest file belongs to the optional directtory named 'META-INF'. This directory is used to store package and extension configuration data, security related data, versioning related data, services related data, etc.

A JAR file can be created by using the 'jar' command line utility OR if you wish to create JAR files programatically then you may use java.util.jar package for required APIs.

Java 1.3 defined a mechanism called JarIndex for optimizing the class searching (in a JAR) process for the classloaders. This mechanism uses INDEX.LIST file of the META-INF directory. Read Next - JarIndex mechanism in Java >>

WAR - Web ARchive

As the name suggests this file format is used to package all the components of a Web Application. It may contain JARs, JSPs, Servlets, HTMLs, GIFs, etc. The purpose of this archive format is same as that of the JAR - to make the deployment, shipping, and in turn the maintenance process easier. This will have an XML file named web.xml as the Deployment Descriptor. This Deployment Descriptor is used by the Web Container to deploy the web application correctly.

EAR - Enterprise ARchive

An enterprise application may be composed of several Web Applications and other independent JARs. This archive file format is used in those cases to bundle all the components of an enterprise application into a single file. Again the purpose is same - making deployment, shipping, and hence the maintenance easier. Since, an enterprise application may have several Web Applications as its components, hence an EAR file may contain WARs and JARs. An EAR also contains an XML-based Deployement Descriptor, which is used by the Application Server to deploy the enterprise application correctly.



Joemon said...

Very good post. Thanks
Please if possible give more informations on each.

Samad said...

very clean concept you depicts.