Java Reference
In-Depth Information
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">
<jboss>
<enterprise-beans>
<session>
<ejb-name>test/Money</ejb-name>
<jndi-name>ejb/Money</jndi-name>
</session>
</enterprise-beans>
<resource-managers>
</resource-managers>
</jboss>
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.
23.2.2
We have put a lot of pieces in place to get a bean that we can call from across
the enterprise. But what does that call look like? How might we make use of
the bean?
The first step is to make contact with the JNDI service and locate the
home interface for the bean. It looks like the section of code in Example 23.5.
Using Our Bean