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

> Procedural Languages > Java

1 - About

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.

Advertising

3 - Management

3.1 - create

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

3.2 - 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
Advertising

3.3 - execute a JAR

java -jar myJAR.jar

3.4 - 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 load

3.5 - search a jar

4 - Structure and Content

4.1 - EAR

An EAR file contains:

where:

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

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

Advertising

4.2 - Module

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:

4.2.1 - EJB

An EJB modules contain:

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

4.2.2 - Web

war

4.2.3 - 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.

4.2.4 - 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.

5 - Documentation / Reference

lang/java/archive.txt · Last modified: 2019/09/11 11:33 by gerardnico