.JAR .WAR and .EAR in Java

Tha main question here is what are jar, war, and ear in java and what is the difference between those. The shortest explanation is
A Java EE application is delivered in a Java Archive (JAR) file, a Web Archive (WAR) file, or an Enterprise Archive (EAR) file
according to Oracle. But this is not the only thing we are looking for today. We need to know more.

What is JAR

JAR stands for Java ARchive. It is like a zip file which keeps several files together. If you have a jar file, you can use a Java Decompiler to see the content in the jar file. See more.

The main motivation for implementing jar was to enable Java applets to download their content in a single HTTP transaction. A jar file can contain .class files, images, and sounds. Jar file format also supports compression as well. Go to JAR File Specification for more detailed information.

What is WAR

WAR stands for Web Application Resource or Web application ARchive. Java EE application can contain several components. All the web components of a Java EE application are packaged in WAR files. Web components are JSPs, Servlets, XML and other resources such as images and etc.

What is EAR

An EAR file contains Java EE modules and, optionally, deployment descriptors. Below is the structure of an EAR.

An EAR can contain several jars and a war file. Those are
  1. EJB modules. which are packaged in a JAR.

  2. Web modules, which is a WAR file.

  3. Application client modules, which is a JAR.

  4. Resource adapter modules, which are packaged as JAR files with a .rar (resource adapter archive) extension.


Actually, A WAR or EAR file is a standard JAR (.jar) file with a .war or .ear extension. So here we are talking about the same file type but with different extensions and purposes. These all 3 types of files makes it easy to gather several Java EE modules together.

All J2EE components are packaged separately and bundled together into an Enterprise Archive (EAR) file for application deployment. As a conclusion and for the ease of remembering things we can say that "EAR is just both JARS and WARS together". It is also important to know the purpose of these each file type as well.

I have gathered some useful links as references. Go through those to learn more. That's how I also learned.
  • https://docs.oracle.com/javaee/6/tutorial/doc/bnaby.html

  • https://docs.oracle.com/cd/E19316-01/820-3748/aduvz/index.html

  • https://docs.oracle.com/cd/E19199-01/816-6774-10/a_war.html

  • https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jarGuide.html

  • https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html

  • https://stackoverflow.com/questions/1594667/war-vs-ear-file