Java Made Clear: Difference between JAR WAR EAR Examples

Basically JAR WAR EAR are compressed files of Java compressed at DOS prompt with jar tool (jar command). They are used for different purposes.

a) JAR File (Java ARchive)

JAR file is like winzip file compressed with JDK software. The problem of popular winzip file is it should be unzipped on Windows OS only. winzip is platform-dependent. A winzip file cannot be opened or unzipped from Linux. For that matter, all zipping algorithms are platform-dependent. The interesting point with JAR file is it can be zipped and unzipped by JVM irrespective of OS. That is, wherever Java is working, the JAR file can be created or unzipped. It can be said, JAR is platform-independent way of creating a zip file.

A JAR file extension is .jar and is created with jar command from command prompt (like javac command is executed). Generally, a JAR file contains Java related resources like libraries, classes etc.; but need not be. It can contain any non-sense (non-related) files like .txt, .doc, .gif etc., just like a winzip can contain.

All the options of JAR command, security aspects, creating JAR file with unzipping are discussed with examples at JAR (Java ARchive) Files.

b) WAR File (Web Application ARchive)

A WAR file is simply a JAR file but contains only Web related Java files (but not Web unrelated files) like Servlets, JSP, HTML, Database Java Beans, web.xml file, Property bundles, JavaScript, shopping carts etc. necessary to develop Web applications. The advantage of WAR file is it can be deployed easily on client machine in a Web server environment. The extension of WAR file is .war but ofcourse created with JAR command only.

To execute a WAR file, a Web server or Web container is required, for example, Tomcat or Weblogic or Websphere. To execute a JAR file, simple JDK is enough.

The IDE tools like Eclipse, JBOSS etc. maintain a directory hierarchy structure for WAR files like WEB-INF folder etc.

Two programs are given on the creation of WAR file.

1. Servlet WAR File in Tomcat with Creation, Deployment, Execution

2. Servlet WAR File in Weblogic Creation and Deployment

c) EAR File (Enterprise Application ARchive)

EAR file contains Enterprise application related files (J2EE) like XML, EJB modules etc. Ir is also created with JAR command only but with extension .ear. EAR file is deployed in an application server.

Advantages JAR, EAR and EAR files

  1. With JAR, EAR and EAR files, the deployment of software is easy on client machines. At a stretch all the related files of an application are installed. For example, Oracle comes with JAR files for distributing Oracle database on CDs etc. IBM uses JAR for installation and documentation for WebSphere.
  2. Easy development and testing


  1. Making minor changes in a Servlet, JSP or EJB requires complete process of remaking and redeployment of jar, war, ear files. It is very tedious to follow the complete process in dynamic environments where data changes very often.

Do you know these are possible with AWT?

Leave a Comment

Your email address will not be published.