J2EE/Java EE File Formats: EAR vs WAR
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.
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.
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 this entry
You’re currently reading “J2EE/Java EE File Formats: EAR vs WAR,” an entry on Singaram's Tech Musings
- June 21, 2011 / 4:27 PM