start page | rating of books | rating of authors | reviews | copyrights

Book Home Enterprise JavaBeans Search this book

10.7. The ejb-jar File

The JAR file format is a platform-independent format for compressing, packaging, and delivering several files together. Based on ZIP file format and the ZLIB compression standards, the JAR ( Java archive) packages and tool were originally developed to make downloads of Java applets more efficient. As a packaging mechanism, however, the JAR file format is a very convenient way to "shrink-wrap" components and other software for delivery to third parties. The original JavaBeans component architecture depends on JAR files for packaging, as does Enterprise JavaBeans. The goal in using the JAR file format in EJB is to package all the classes and interfaces associated with one or more beans, including the deployment descriptor, into one file.

The JAR file is created using a vendor-specific tool, or using the jar utility that is part of the Java 2, Standard Edition development kit. An ejb-jar file contains:

The XML deployment descriptor must be located in the path META-INF/ejb-jar.xml, and must contain all the deployment information for all the beans in the ejb-jar file. For each bean declared in the XML deployment descriptor, the ejb-jar file must contain its bean class, remote and home interfaces, and dependent classes and interfaces. Dependent classes and interfaces are usually things like application-specific exceptions, business interfaces, and other super types, and dependent objects that are used by the bean. In the ejb-jar file for the TravelAgent bean, for example, we would include the IncompleteConversationalState application exception and the Ticket and CreditCard classes, as well as the remote and home interfaces to other beans referenced by the TravelAgent bean, like the Customer and ProcessPayment bean.[1]

[1]The EJB 1.1 specification also allows remote and home interfaces of referenced beans to be named in the manifest's Class-Path attribute, instead of including them in the JAR file. Use of the Class-Path entry in the JAR's manifest is addressed in more detail in the Java 2, Standard Edition specification.

The jarutility can be used from the command line to package a bean in a JAR file. Here is an example of how the jar utility was used to package the Cabin bean in Chapter 4, "Developing Your First Enterprise Beans":

\dev % jar cf cabin.jar com/titan/cabin/*.class META-INF/ejb-jar.xml

F:\..\dev>jar cf cabin.jar com\titan\cabin\*.class META-INF\ejb-jar.xml

You might have to create the META-INFdirectory first, and copy ejb-jar.xml into that directory. The c option tells the jar utility to create a new JAR file that contains the files indicated in subsequent parameters. It also tells the jar utility to stream the resulting JAR file to standard output. The f option tells jar to redirect the standard output to a new file named in the second parameter (cabin.jar). It's important to get the order of the option letters and the command-line parameters to match. You can learn more about the jar utility and the java.util.zip package in Java™ in a Nutshell by David Flanagan (O'Reilly), or Learning Java™, by Pat Niemeyer and Jonathan Knudsen (formerly Exploring Java , also published by O'Reilly).

The jar utility creates the file cabin.jar in the dev directory. If you're interested in looking at the contents of the JAR file, you can use any standard ZIP application (WinZip, PKZIP, etc.), or you can use the command jartvfcabin.jar.

10.7.1. The client-jar File

EJB 1.1 also allows for a client-jar file, which includes only the interfaces and classes need by a client application to access a bean. This would include the remote and home interfaces, primary key, and any dependent types that the client is exposed to, such as application exceptions. The specification does not say how this is delivered to the client, what exactly it contains, or how it is packaged with the ejb-jar file. In other words, the client-jar file is a fairly vendor-specific concept in EJB.



Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.