JAR
and WAR
are extensions of platform-independent archive files for Java applications. There is also a third format known as EAR
. All these formats are essentially ZIP archives containing classes and other parts of an application. You can rename such a file to .zip
, decompress it, and see what's inside.JAR – Java Archive. It contains class files, resources, dependent libraries, and other files necessary for the application. It may contain an entry point and can be used as the execution target for
java
command.WAR – Web Archive. Technically, it has the same structure, but serves a different purpose — it's a JavaEE web component archive. It usually contains JARs with implementations, JSPs, static frontend files, and servlet container meta-information (
web.xml
). It is primarily used for deploying web applications to servlet containers. With the advent of Servlet API 3.0 and embedded containers, it's becoming more common to package even web components into self-sufficient JARs (as per Spring Boot's motto: Make jar, not war).EAR – Enterprise Archive. For developers who started their careers in the era of the Spring Framework, this might seem quite exotic. It is a monolithic JavaEE application assembled into one. It contains deployment descriptors and JavaEE modules (web modules, EJBs, client modules, resource adapters). It is deployed on a JavaEE Application Server.
All three file types are assembled using the
jar
from JDK.