Java Reference
In-Depth Information
4.1.1
Java EE applications
In the simplest sense, Java
EE
EAR
s can be thought of as bigger versions of Java
SE
JAR
s.
EAR
s are in zip format, like
JAR
s, but rather than containing Java classes, they
contain enterprise modules such as
WAR
s and
EJB
JAR
s. One other key difference
between
EAR
s and
JAR
s is that an
EAR
contains an application descriptor called
META-
INF
/application.xml rather than a standard manifest.
Listing 4.1
A simple application.xml
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/application_5.xsd"
version="5">
<display-name>My EAR Application</display-name>
<description>An example EAR</description>
Included
EJB
<module>
<ejb>ejb_module.jar</ejb>
</module>
Included
WAR
<module>
<web>
<web-uri>war_module.war</web-uri>
<context-root>/migration</context-root>
</web>
</module>
Configuration
for WAR
Folder for
utility JARs
<library-directory>shared</library-directory>
</application>
The application
XML
descriptor in listing 4.1 shows how a Java
EE
EAR
provides a
complete list of the content of the application (the
WAR
s,
EJB
s, and library
JAR
s that
make up the application) and it can also contain security metadata. While it's possi-
ble for the application.xml to reference a module that isn't contained directly within
the
EAR
, this is an extremely uncommon practice. Often the application.xml is used
to do no more than restate the contents of the
EAR
and to provide context roots for
any web modules.
Improvements to the EAR model
Starting with Java EE 5, the application.xml descriptor became optional, only being
specified if you needed to override any defaults. This helps to reduce the duplication
typically present in the EAR metadata as modules inside an EAR no longer need to
be listed in application.xml as well.

















