This chapter looks at one of the principal types of component in the Java 2 Platform, Enterprise Edition (J2EE) — Enterprise JavaBeans (EJBs). See how EJBs are applied and how they are deployed. (This is chapter 4 from Sams Publishers, author Martin Bond, et. al., Teach Yourself J2EE in 21 Days, second edition, ISBN: 0-672-32558-6).
All of the EJB classes and the deployment descriptor should be bundled up in a JAR file. The deployment descriptor is stored in a META-INF directory (the same location as the JAR manifest file) and must be named ejb-jar.xml. If there are multiple EJBs packaged in the same JAR file, the deployment descriptor will have multiple EJB definitions in it. The JAR file is then termed an EJB-JAR file to denote its payload. The JAR file itself can be called anything (but obviously a name appropriate to the application makes most sense) and conventionally has a .jar file extension.
The EJB-JAR file can also contain any extra resources required by the EJB, such as platform-specific configuration information that does not fit in the standard deployment descriptor.
Typical contents of a platform specific deployment descriptor are
The JNDI name the EJB must be deployed under Mappings between resources referenced in the J2EE components such as EJBs and the actual resources within the J2EE server
An EJB-JAR file can store more than one platform-specific deployment descriptor file, enabling it to be used with different J2EE implementations. Although the EJB-JAR file is now complete, it must form part of an application to serve a useful purpose. J2EE defines that enterprise applications can be built from components (Web, EJB, and Client Application components). Therefore, a second JAR file is used to bundle these J2EE components into a complete J2EE Application, this is called the Enterprise Archive file.
The Enterprise Archive File
The Enterprise Archive (EAR) file contains a number of J2EE components comprising an application and yet another deployment descriptor. This descriptor includes a description of the application, which components it uses, how those components relate to each other, and which specific resources they use. This is the information provided by the Application Assembler and Deployer.
The application deployment descriptor is also an XML document, called application.xml, and it is stored in the META-INF directory of the Enterprise Archive (which although a JAR file the Enterprise Archive typically has a filename extension of .ear not .jar). Listing 4.6 shows the application.xml descriptor for the Agency application.
The application.xml file just lists the modules that form the enterprise application, in this case the single Agency EJB contained in agency-session-ejb.jar.
An EAR file may also contain one or more platform-specific deployment descriptors for the application enabling it to be used with different J2EE implementations.
This chapter is from Teach Yourself J2EE in 21 Days, second edition, by Martin Bond et. al. (Sams, 2004, ISBN: 0-672-32558-6). Check it out at your favorite bookstore today. Buy this book now.