Tuesday, November 15, 2005

EAR file

An Enterprise Archive File (EAR) is a convenient way to bundle up all the pieces of a full-fledged J2EE application. An EAR keeps everything organized.

An EAR can contain at least one of any of the following modules. You can safely omit any of them, if they aren't needed.
  • Web module - A WAR file containing presentation tier components
  • EJB module - An EJB JAR file containing the middle-tier components (EJBs)
  • Java module - A regular JAR file containing classes and libraries that are shared across the entire application. An application client JAR and a common JAR are two examples
    of Java modules
Application.xml Just as a WAR file contains a web.xml deployment descriptor, an EAR file contains a file named application.xml. It is essentially a packing list, telling the J2EE server exactly what files the EAR contains and where you can find the files relative to the root of the EAR. The EAR file's META-INF directory stores application.xml.

An example application.xml file:
<?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"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
version="1.4">
<display-name>JBossAtWorkEAR</display-name>
<module>
<web>
<web-uri>webapp.war</web-uri>
<context-root>jaw</context-root>
</web>
</module>
<module>
<java>common.jar</java>
</module>
</application>
The elements in application.xml should be pretty self-explanatory. We are telling the application server the name of each JAR and what function it serves. Notice that Web modules allow you to specify one other value - the <context-root>. The context root is your web site's URL. If you deploy a simple WAR file, the name of the WAR will be used as the URL. When your WAR file is deployed inside an EAR, this element allows you to override the physical name of the WAR and use whatever URL you'd like.

Hat Tip: Oreilly's book: JBoss at Work - A Practical Guide by Tom Marrs & Scott Davis
Technorati Tags: ,
Blogs linking to this article

0 Comments:

Post a Comment

<< Home