Java - Packaging, Archive, Library (JAR, WAR, EAR File)


For deployment purpose, J2EE applications are delivered and reside in Archive files (or unit).

A RAR, WAR or EAR file is a standard JAR (.jar) file with a .war or .ear extension. Each archive extension file denotes its purpose. A JAR (Java ARchive) file format is based on the standard ZIP file format with an optional manifest file.

J2EE Archive Type File Extension Module Type
Enterprise Archive EAR All modules together
Java Archive JAR Enterprise Bean Module, Application Client module
Web Archive WAR Web module
Resource Adapter RAR Ressource Adapter module

A J2EE archive is composed of:

Using modules and JAR, WAR, EAR files makes it possible to assemble a number of different J2EE applications using some of the same components. No extra coding is needed; it is just a matter of assembling various J2EE modules into Java EE JAR, WAR, or EAR files.



You can create/archiving JAR files, either:

  • by using the JAR utility directly,
  • through an IDE such as Oracle JDeveloper, Eclipse, …
  • or by using the ant utility and a build.xml file.

Creating a jar-file is not very difficult. But creating a startable jar-file needs more steps:

echo Main-Class: com.gerardnico.HelloWorld>myManifest
md build\jar
jar cfm build\jar\HelloWorld.jar myManifest -C build\classes

unpack an archive

The following command will unpack the archive in the current directory

jar xvf myArchive.ear

The following command will unpack all ear archive in the current directory

jar xvf *.ear

execute a JAR

java -jar myJAR.jar

load dynamically a JAR

See The System class contains a means of loading files and libraries with the methods (load and loadlibrary). For a class, see Java - Class (Definition)

search a jar


Structure and Content


An EAR file contains:


  • the directory META-INF contains the configuration files (deployment descriptors, manifest). <note tip>META-INF is WEB-INF for a Web module.</note>

The MANIFEST.MF files are created automatically by the JAR utility


A Java EE module consists of:

  • one or more Java EE components for the same container type (Ejb, Web component, …)
  • and, optionally, one component deployment descriptor of that type.

A Java EE module can be deployed as a stand-alone module.

Java EE modules are of the following types:


An EJB modules contain:

EJB modules are packaged as JAR files with a .jar extension.


Application client

Application client modules contain:

  • class files
  • and an application client deployment descriptor.

Application client modules are packaged as JAR files with a .jar extension.

Resource adapter

Resource adapter modules contain:

  • all Java interfaces,
  • classes,
  • native libraries,
  • and other documentation,
  • along with the resource adapter deployment descriptor.

Together, these implement the Connector architecture for a particular EIS.

Resource adapter modules are packaged as JAR files with an .rar (resource adapter archive) extension.

Documentation / Reference

Powered by ComboStrap