J2EE/Java EE File Formats: EAR vs WAR


Overview

J2EE application server has two containers (run time environments) – one is web container and other is EJB container

Web container hosts web applications based on JSP/Servlets API – designed specifically for web request handling – more of request/response distributed computing. Web container requires the web module to be packaged in WAR file that is special JAR file with web.xml file in WEB-INF folder

EJB container hosts enterprise java beans based on EJB API designed to provide extended business functionality such as declarative transactions, declarative method level security and multi protocol support – more of RPC style of distributed computing. EJB container required EJB module to be packaged in JAR file having ejb-jar.xml file in META-INF folder.

WAR

According to Wikipedia,

A WAR file is a JAR file used to distribute a collection of JavaServer Pages, Servlets, Java classes, XML files, tag libraries and static Web pages (HTML and related files) that together constitute a Web application.

One disadvantage of web deployment using WAR files in very dynamic environments is that minor changes cannot be made during runtime. Any change whatsoever requires regenerating and redeploying the entire WAR file. Most JEE web containers allow web applications to be deployed as a directory instead of a single file. This is known as an exploded archive. An exploded archive may be used during development to quickly test changes to a web application.

EAR

According to Wikipedia,

An Enterprise Archive, or EAR, is a file format used by Java EE for packaging one or more modules into a single archive so that the deployment of the various modules onto an application server happens simultaneously and coherently.

Developers can embed various artifacts within an EAR file for deployment by application servers:

1. A Web module has a .war extension. It is a deployable unit that consists of one or more web components, other resources, and a web application deployment descriptor. The web module is contained in a hierarchy of directories and files in a standard web application format. 2. POJO Java classes may be deployed in .jar files.
3. An Enterprise Java Bean module has a .jar extension, and contains in its own META-INF directory descriptors describing the persistent classes deployed. Deployed entity beans become visible to other components and, if remotely exported, to remote clients. Message Beans and Session Beans are available for remote access. 4. A Resource Adapter module has a .rar extension.

In short, EAR files generally contain configurations such as application security role mapping, EJB reference mapping and context root url mapping of web modules. Apart from web modules and EJB modules, EAR files can also contain connector modules packaged as RAR files and Client modules packaged as JAR files.

About these ads

2 comments

  1. [...] J2EE/Java EE File Formats: EAR vs WAR (singztechmusings.wordpress.com) [...]

  2. [...] J2EE/Java EE File Formats: EAR vs WAR (singztechmusings.wordpress.com) [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 27 other followers

%d bloggers like this: