What is the difference between JAR,WAR and EAR files
JAR file : JAR stands for Java Archive. A jar file is used to store class files. These classes can be imported by other code and methods, member variables and inner classes can be accessed from those class files present in the jar files. In fact, a jar file is nothing but a zip file with file extension changed to .jar.
Optionally, one can also sign jar files to add authenticity to them. The things that make a zip file jar are:
- Presence of class files in packages (folders)
- File extension of .jar
- Optional META-INF folder and META-INF/MANIFEST.MF file
WAR file : WAR stands for Web Archive. WAR files are used to package java web applications. There is a special structure which needs to be followed for web applications. When the application folder and files are zipped then the file can renamed with file extension of .WAR. The advantage of using WAR files is that Java EE based web applications can be sent from one place to another in packaged form. A WAR file can also contain multiple JAR files (usually present in the WEB-INF/lib folder inside the WAR).
EAR file : EAR stands for Enterprise Archive. The EAR files contain the EJB/JPA based packaged applications. The contents of a typical ear file contains a war file, jar file and JAVA EE specific deployment descriptors. In effect, EAR file is also a zip file containing other zip files (war and jar) and some files(deployment descriptor).
Note that JAR file can be made executable. WAR and EAR files are used for packaged deployment on servers where the server automatically expands the WAR and EAR file and deploys the application for use. The JAR tool present in $JAVA_HOME/bin folder can be used to create JAR, WAR or EAR files from folders.