2.1.1. Assembling Applications
As discussed in the introduction to this chapter, we've intentionally made the distinction
between assembling and deploying applications because they really are two distinct stages
in getting a J2EE application up and running. Assembling an application involves getting
all of the elements of the application together in the right package structure and with the
right configuration information included. Deploying an application is the act of taking the
application assembly and plugging it into the application server environment so that it can
The first step in assembling an application is to assemble the component modules that
make up the application. Once this is accomplished, you package up the component
modules into an application archive.
An application is fully assembled once all of its component modules have been pulled
together into an application archive, as shown in Figure 2-2. In the example shown, the
application archive contains two component modules, a web module and an EJB module.
Each component module contains a deployment descriptor describing the components
themselves, how they should be managed by the container at runtime, and references to
any resources or other components that the module's components require in order to
The application assembly itself also includes an application.xml deployment descriptor,
which references all of the modules that make up the application.
At this point, the application is assembled but not deployed. All of the resource references
in the component module descriptors are dangling, unresolved—we can't assign actual
resources to these references until we put the application into a physical server
It is possible to resolve some internal component references at this point, if
they reside in the same application assembly. For example, if one of the component
modules in Figure 2-2 references an EJB component and that EJB component is contained
in the other component module, we can specify that internal reference directly in the
deployment descriptor of the referring component. But for other resources, like JDBC
DataSources and JavaMail Sessions, we won't be able to connect the deployment
descriptor references to actual resources until we know the application server into which
we're deploying and how its resources are configured internally.
This separation of assembly and deployment of components and applications, using
deployment descriptors as the mediator between these two stages, helps you
Figure 2-2. Assembled application archive
to develop enterprise applications that migrate easily across environments. You may be
writing a shopping cart application, for example, with an EJB component that requires a
database connection in order to store and update order items. You might be developing
this application in a development environment using a MySQL database but need to run
it in a production environment using an Oracle database.
The database requirement can be specified clearly as a reference to a DataSource in the EJB deployment descriptor when the application is assembled. When the application is deployed to the development environment, the DataSource reference can be bound to a DataSource configured against the MySQL database. When the application is eventually deployed to production, the same application assembly can be used, but the resource reference will now be bound to a DataSource configured to connect to the production Oracle database.