Step 3: the deployment descriptor

ow it's time to create the deployment descriptor. As a reminder, this file tells the EJB server which classes form the Bean, the home interface and the remote interface. If there is more than one Bean in the package, it indicates also how the Beans interact with one another. In this simple example, there is only one Bean so we won't need to worry about that part.
       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:

ejb-jar.xml: deployment descriptor for the Interest Bean


 
<?xml version="1.0" encoding="Cp1252"?>
<ejb-jar>
     <description>jBoss test application</description>
     <display-name>Test</display-name>
     <enterprise-beans>
       <session>
	 <ejb-name>Interest</ejb-name>
	 <home>com.web_tomorrow.interest.InterestHome</home>
	 <remote>com.web_tomorrow.interest.Interest</remote>
	 <ejb-class>com.web_tomorrow.interest.InterestBean</ejb-class>
	 <session-type>Stateless</session-type>
	 <transaction-type>Bean</transaction-type>
       </session>
     </enterprise-beans>
   </ejb-jar>
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), which won't work.
       In principle what we deploy on the server is an application, not a Bean. In this example our application consists of exactly one Bean, so it comes to the same thing. In the deployment descriptor, the section
<ejb-name>Interest</ejb-name>
assigns a name to the Bean; in practice client applications won't use this name, they will use the Bean's JNDI name, which is assigned in a different file. The JNDI name will often be in the form `[application name]/[bean name]', which is what we shall use later.
       Although the deployment descriptor format is common to all EJB servers, it doesn't provide all the information that the server needs to deploy the bean. Specifically it does not know how to map package names to JNDI names. The server may also need to be told how to manage persistence and state. There is, as yet, no standard way of specifying these things, and every server implementation does it differently. There isn't even a standard name for this procedure. The approach taken by jBoss is that the Bean package should provide an additional XML file, called jboss.xml in the same directory as the deployment descriptor. The format of jboss.xml is largely undocumented, but it's straightforward. The first part of the file lists the Beans and their JNDI names, and refers to configuration sections in the second part of the file. It should only be necessary to edit the first part. In the listings below I have divided the jboss.xml file into two parts to make the distinction clear; of course you need both these parts in the same file in practice.

jboss.xml: first part (this bit provided by the Bean developer)


 
<jboss>
     <enterprise-beans>
		<session>
	 	<ejb-name>Interest</ejb-name>
	 	<jndi-name>interest/Interest</jndi-name>
	 	<configuration-name>Defaugt Stateless SessionBean</configuration-name>
       	</session>
        <secure>false</secure>
     </enterprise-beans>

All this file says is that the Bean called Interest is assigned the JNDI name of interest/Interest and has the server configuration Defaugt Stateless SessionBean. This configuration refers to a section in the second part of the file. I don't know in detail what this section does, and I don't particularly want to! Here it is, anyway:

jboss.xml: second part (this bit should not need to be edited)


 
     <resource-managers />
     <container-configurations>
       <container-configuration configuration-class="org.jboss.ejb.deployment.EntityContainerConfiguration">
	 <container-name>BMP EntityBean</container-name>
	 <container-invoker>org.jboss.ejb.plugins.jrmp13.server.JRMPContainerInvoker</container-invoker>
	 <instance-pool>org.jboss.ejb.plugins.EntityInstancePool</instance-pool>
	 <instance-cache>org.jboss.ejb.plugins.NoPassivationEntityInstanceCache</instance-cache>
	 <persistence-manager>org.jboss.ejb.plugins.BMPPersistenceManager</persistence-manager>
	 <transaction-manager>org.jboss.tm.TxManager</transaction-manager>
	 <container-invoker-conf>
	   <Optimized>False</Optimized>
	 </container-invoker-conf>
	 <container-cache-conf />
	 <container-pool-conf>
	   <MaximumSize>100</MaximumSize>
	   <MinimumSize>10</MinimumSize>
	 </container-pool-conf>
       </container-configuration>
       <container-configuration configuration-class="org.jboss.ejb.deployment.StatelessSessionContainerConfiguration">
	 <container-name>Singleton Stateless SessionBean</container-name>
	 <container-invoker>org.jboss.ejb.plugins.jrmp13.server.JRMPContainerInvoker</container-invoker>
	 <instance-pool>org.jboss.ejb.plugins.SingletonStatelessSessionInstancePool</instance-pool>
	 <instance-cache></instance-cache>
	 <persistence-manager></persistence-manager>
	 <transaction-manager>org.jboss.tm.TxManager</transaction-manager>
	 <container-invoker-conf>
	   <Optimized>False</Optimized>
	 </container-invoker-conf>
       </container-configuration>
       <container-configuration configuration-class="org.jboss.ejb.deployment.EntityContainerConfiguration">
	 <container-name>CMP EntityBean</container-name>
	 <container-invoker>org.jboss.ejb.plugins.jrmp13.server.JRMPContainerInvoker</container-invoker>
	 <instance-pool>org.jboss.ejb.plugins.EntityInstancePool</instance-pool>
	 <instance-cache>org.jboss.ejb.plugins.NoPassivationEntityInstanceCache</instance-cache>
	 <persistence-manager>org.jboss.ejb.plugins.jaws.JAWSPersistenceManager</persistence-manager>
	 <transaction-manager>org.jboss.tm.TxManager</transaction-manager>
	 <container-invoker-conf>
	   <Optimized>False</Optimized>
	 </container-invoker-conf>
	 <container-cache-conf />
	 <container-pool-conf>
	   <MaximumSize>100</MaximumSize>
	   <MinimumSize>10</MinimumSize>
	 </container-pool-conf>
       </container-configuration>
       <container-configuration configuration-class="org.jboss.ejb.deployment.StatelessSessionContainerConfiguration">
	 <container-name>Defaugt Stateless SessionBean</container-name>
	 <container-invoker>org.jboss.ejb.plugins.jrmp13.server.JRMPContainerInvoker</container-invoker>
	 <instance-pool>org.jboss.ejb.plugins.StatelessSessionInstancePool</instance-pool>
	 <instance-cache></instance-cache>
	 <persistence-manager></persistence-manager>
	 <transaction-manager>org.jboss.tm.TxManager</transaction-manager>
	 <container-invoker-conf>
	   <Optimized>False</Optimized>
	 </container-invoker-conf>
	 <container-pool-conf>
	   <MaximumSize>100</MaximumSize>
	   <MinimumSize>10</MinimumSize>
	 </container-pool-conf>
       </container-configuration>
     </container-configurations>
   </jboss>


       So now we've got the deployment descriptor ejb-jar.xml, the run-time configuration file jboss.xml and the classes. It's time to package them together.

©1994-2003 Kevin Boone, all rights reserved