Hi,

Jay SenSharma

Jay SenSharma

An EAR file provides a convenient way to bundle up all pieces of a J2EE application. It may contain Java Module, WAR Module or an EJB Jar module.

An EAR can contain at least any one of these modules. EAR may contain more Modules as well.

Every EAR must have a Valid java/web/ejb module along with “META-INF/application.xml” file. “application.xml” file is the Main EAR deployment descriptor file, Which contains the Informations about the Different types of Modules available as part of the EAR appication.

What an EAR contains?

Web module
A WAR file containing the view logics like JSPs, Servlets, Html contents. Every web module must have one Web Deployment descriptor placed inside “WEB-INF/web.xml”

EJB module
An EJB JAR file containing the model components, Model Components are the actual Business logic components which has a Logic/Code to perform the actual Business tasks. Like Inserting/Updating/Deleting data in the database, Starting and Commiting the Transactions, Sending/receving Messages and processing themΒ  etc…
(EJBs, MDBs, etc.)

Java module
It’s a rarely used Module which is actually a Pure JAR file containing classes and libraries (xml/properties…etc) that are shared across the entire application (WAR/EJB-Jar available as part of the EAR). In case of weblogic Server it is always better to deploy these Jars on Server as an “Optional Package” to share the Same Jar resources with Multiple applications. For more informations on Optional Packages Please refer to: http://middlewaremagic.com/weblogic/2009/12/06/optional-packages/

What is Structure of a Standard EAR Application?

Standard EAR Diagram with One WAR & One EJB JAR

Standard EAR Diagram with One WAR & One EJB JAR

What is the use of “APP-INF/lib” and “WEB-INF/lib” directory?

Suppose if we have an EAR application which contains WebApp1.war, WebApp2.war, EJB1.jar and EJB2.jar. Now suppose all these Modules want to use some classes which is available as part of a Jar “common.jar”. So in this case it is better to Place “common.jar” file inside “APP-INF/lib” directory, like this we need not to put the same Jar 4 times inside each and every Modules.
Similarly if we have some common *.class files which we want to share between all the Modules which are available as part of an EAR application …then in that case we can put those “*.class” files inside “APP-INF/classes” directory.

NOTE: Never put a Jar file inside “APP-INF/classes”, because it is intended to be placed only *.class files.
Similarly Never put a *.class file inside “APP-INF/lib”, because “APP-INF/lib” is intended to be Placed Jar files only.

What does the “META-INF/application.xml” file contains?

“application.xml” file contains the information about the different types of modules available as part of our EAR application. below is the Simple example of this file which contains two Modules “WebApp1.war” and “EJB1.jar”.

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4">
<description>Test EAR Example</description>
<display-name>TestEAR Example</display-name>

<module>
<ejb>EJB1.jar</ejb>
</module>

<module>
<web>
<web-uri>WebApp1.war</web-uri>
<context-root>WebApp1ContextRoot</context-root>
</web>
</module>

</application>

.

.
Thanks
Jay SenSharma

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.