< Zurück | Inhalt | Weiter >

23.2.1 What’s in an EJB-JAR File

Let’s look first at the content of the JAR file. After that we’ll look at the specifics of the XML descriptor files.

$ jar xf budgetpro.ear # unjar the EAR

$ ls # see what we got


budgetpro.ear budgetpro.jar budgetpro.war

$ jar tf *.jar # list the JAR contents META-INF/


com/ com/jadol/

com/jadol/budgetpro/ net/

net/multitool/ net/multitool/util/

com/jadol/budgetpro/MoneyLocal.class com/jadol/budgetpro/SessionTestServlet.class

com/jadol/budgetpro/MoneyEJBean.class com/jadol/budgetpro/MoneyHome.class com/jadol/budgetpro/Money.class com/jadol/budgetpro/MoneyLocalHome.class com/jadol/budgetpro/TestMoneyEJBean.class net/multitool/util/Save.class net/multitool/util/Cost.class net/multitool/util/Debt.class net/multitool/util/SAMoney.class

META-INF/ejb-jar.xml META-INF/jboss.xml


The EJB-JAR file contains the specifics for our EJB file (Table 23.2).

To keep Table 23.2 simpler and shorter, we didn’t list each of the directo- ries in the tree of directories down to each class file. When we show, for exam- ple, com/jadol/budgetpro/*, realize that each directory that is part of that structure (com, com/jadol, and so on) is part of the JAR file. The class files are located in that tree.

So what are the two XML files?

These XML files provide the EJB container with information on how the bean parts are wired together. Let’s look at the contents of each.

Table 23.2 Contents of the EJB-JAR file








net/multitool/util/* com/jadol/budgetpro/* META-INF


text XML


class files class files directory


A standard JAR manifest; besides defining the JAR version it can be empty.

A description of the EJB, most importantly the mapping between the name of the EJB and the actual Java class file.

This file is specific to JBoss (well, duh!). It describes a mapping between the JNDI name used in the locate() and the name of the EJB. The equivalent file for Geronimo (which uses OpenEJB) is openejb-jar.xml.

Various classes. Various classes.

A directory with other files.

The ejb-jar.xml file (Example 23.3) is part of the J2EE standard. It specifies the names of the home and remote (and local, if any) interfaces, the implementation class (i.e., the real bean) and the name for the bean.


Example 23.3 Sample ejb-jar.xml file

<?xml version="1.0" encoding="UTF-8"?>


"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">





<!-- Session Beans -->

<session id="test_Money">

<display-name>Test Money Bean</display-name>













The name of the bean defined in the ejb-jar.xml file is not, however, the name we will use in our JNDI lookup. Rather, there is one more level of mapping used by JBoss. Look at the contents of the jboss.xml file (Example 23.4).


Example 23.4 Sample jboss.xml file

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS//EN" "http://www.jboss.org/j2ee/dtd/jboss.dtd">












The two tags define the mapping: You use the jndi-name in the lookup() method and it will (try to) find the EJB named with the ejb-name tag. The ejb-name tag is also used in the ejb-jar.xml file. This provides the association between the two, and the mapping from the JNDI name to EJB is thereby defined.

To summarize, if we want to build an EJB-JAR file, we will need to gather all the class files in their appropriate classpath directory structures. Then we will need to write two XML files and place them in the META-INF directory along with the MANIFEST.MF file. The two XML files will define the EJB pieces and provide a name mapping for locating this bean. Then put all these pieces together into a JAR file, and you have an EJB-JAR file.