📄 ch01s12.html
字号:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>The deployment descriptor</title><link rel="stylesheet" href="styles.css" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/styles.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets Vimages/callouts/"><link rel="home" href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html" title="JBoss 3.0 Documentation"><link rel="up" href="ch01.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01.html" title="Chapter 1. First steps"><link rel="previous" href="ch01s11.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01s11.html" title="Review the EJB Classes"><link rel="next" href="ch01s14.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01s14.html" title="Packaging and deploying the bean"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="jboss.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/jboss.gif" border="0"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch01.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch01s11.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01s11.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch01s14.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01s14.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table><div class="section"><a name="d0e300"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="d0e300"></a>The deployment descriptor</h2></div></div><p>Now it's time to view the deployment descriptor. As a reminder, this
file tells the EJB server which classes make up the bean implementation, the home interface and
the remote interface. If there is more than one EJB in the package, it
indicates also how the EJBs interact with one another. In this simple
example, there is only one EJB so we won't need to worry about that
part.</p><p>Most commercial EJB servers are supplied with graphical tools for
constructing the deployment descriptor. JBoss does have an XML editor, but
it's just as easy to construct the deployment descriptor manually. Here it
is:</p><div class="figure"><p><a name="d0e307"></a><b>Figure 1.6. Deployment descriptor for the Interest Bean</b></p><div class="literallayout"><br>
<?xml version="1.0" encoding="UTF-8"?><br>
<br>
<ejb-jar><br>
<description>JBoss Interest Sample Application</description><br>
<display-name>Interest EJB</display-name><br>
<enterprise-beans><br>
<session><br>
<ejb-name>Interest</ejb-name><br>
<home>org.jboss.docs.interest.InterestHome</home><br>
<remote>org.jboss.docs.interest.Interest</remote><br>
<ejb-class>org.jboss.docs.interest.InterestBean</ejb-class><br>
<session-type>Stateless</session-type><br>
<transaction-type>Bean</transaction-type><br>
</session><br>
</enterprise-beans><br>
</ejb-jar><br>
</div></div><p>The deployment descriptor must be called ejb-jar.xml and it must be in
the directory ./META-INF. A common mistake is to name this directory
`META_INF' (with an underscore, rather than a dash) or meta-inf
which won't work.</p><p>In principle what we deploy on the server is an application, not a
single EJB. In this example our application consists of only one EJB. In the deployment
descriptor, the section <ejb-name>Interest</ejb-name> assigns a name to the
EJB. JBoss by default will put the bean's home interface under the ejb-name
moniker in the JNDI namespace if you don't override this default behavior.</p><p>In practice client applications are not forced to use this name.
Typically a developer will not bother with specifying a different name for the
JNDI namespace. However a production installation of a complete application
comprising many beans, will usually use a different name rather than the one
specified by the developer. Typically this would be something like "[application name]/[bean
name]", which is what we shall use later.</p><p>Although the deployment descriptor format of the ejb-jar.xml file is
common to all EJB servers, and precisely defined by a DTD you can get from
Sun, it doesn't specify everything necessary for a particular EJB server.
Specifically it does not indicate how to map ejb-name to a deployment JNDI name
such as "[application name]/[bean name]".</p><p>The approach taken by JBoss is to provide a default behaviour that
works from the ejb-jar.xml file in most cases. In case of advanced configurations
you need to define JBoss specific behavior using a jboss.xml deployment descriptor.
Refer to the advanced configuration section for the complete details of jboss.xml
descriptor. The only item we will configure via the jboss.xml descriptor is the JNDI
name used to access the Interest EJB home interface.</p><p>By default the JNDI name used to access an EJB's home interface is
the same as the ejb-name value from ejb-jar.xml. For this example that
means that the Interest bean would be located under the JNDI InitialContext
as "Interest". We want to have the home interface available using "interest/Interest"
so we need to specifiy this using the jboss.xml descriptor.</p><div class="section"><a name="d0e324"></a><div class="titlepage"><div><h3 class="title"><a name="d0e324"></a>Overriding the default JNDI name in jboss.xml</h3></div></div><p>To override the default behavior of using the ejb-jar.xml ejb-name element
value as the JNDI name of a bean's home interface, you need to specify
what JNDI name should be used using a jboss.xml descriptor like the following:</p><div class="figure"><p><a name="d0e329"></a><b>Figure 1.7. The JBoss XML descriptor.</b></p><div class="literallayout"><br>
<?xml version="1.0" encoding="UTF-8"?><br>
<jboss><br>
<enterprise-beans><br>
<session><br>
<ejb-name>Interest</ejb-name><br>
<jndi-name>interest/Interest</jndi-name><br>
</session><br>
</enterprise-beans><br>
</jboss><br>
</div></div><p>All this file says is that the Bean called Interest is to be bound under the JNDI
name of interest/Interest.</p><p>So now we've created the standard ejb-jar.xml deployment descriptor as well as
the JBoss specific jboss.xml to set the JNDI name of the Interest EJB home
interface to "interest/Interest". We also have the EJB classes and so we have
all that we need to create the EJB jar package.</p></div></div><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="432" height="79"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch01.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch01s11.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01s11.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch01s14.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01s14.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -