In the last chapter we introduced you to web applications, but the web tier is just one part of the J2EE spectrum. In this chapter, we’ll expand the JAW application from a simple WAR file into a full-fledged EAR.
We’ll explore the different parts of an EAR file. We’ll build a Common JAR containing classes that can be shared across all tiers of the application. Finally, we’ll play with various Ant and XDoclet tasks to create our EAR and dynamically generate the deployment descriptors JBoss needs.
The WAR file is a convenient way to bundle up all pieces of a web application. All servlet containers know how to deploy a WAR file—they expand the bundle, look for the WEB-INF directory, and read the web.xml found there for further deployment instructions.
The EAR file provides the same type of functionality for a full-fledged J2EE application. JBoss expands the EAR, finds the required deployment descriptors, and proceeds from there.
An EAR is like a carton of eggs—it keeps everything organized. While the carton doesn’t add any direct value to your omelet, it makes getting the eggs home from the store so easy that you wouldn’t think about transporting eggs any other way.
Each egg in your EAR carton is a specific piece of the J2EE puzzle. These eggs (or JARs) come in three basic varieties called “modules”:
A WAR file containing presentation tier components
An EJB JAR file containing the middle-tier components (EJBs, MDBs, ...