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.
WAR File (Web Application ARchive)
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.
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
- 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.
- Easy development and testing
- 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.