Article

Enterprise Java Beans, A Primer: Part 2, Implement Your First EJBs

Page: 1 2 3 4 5 Next

Deploying a Session Bean

Once you've written and compiled the source code for your session bean, you must deploy it into the EJB container's environment. This involves describing your EJB type, your desired transaction type, the EJB's home class, the EJB's remote class, and other information. The deployment descriptor is used to contain these descriptions.

The Deployment Descriptor

To deploy an EJB into an EJB container's environment, you must supply a deployment descriptor file to the EJB container. A deployment descriptor file is an XML document, named ejb-jar.xml, that specifies information about the bean such as its persistence type and transaction attributes. An EJB's class files and deployment descriptor must be packaged into a JAR or EAR file.

The following is an example of a deployment descriptor for our session bean:

<?xml version="1.0" encoding="UTF-8"?>  
 
<ejb-jar>  
 <description>A simple session bean</description>  
 <display-name>Simple Message EJB</display-name>  
 <enterprise-beans>  
   <session>  
     <ejb-name>SimpleMessenger</ejb-name>  
     <home>com.jeffhanson.ejb.SimpleMessengerHome</home>  
     <remote>com.jeffhanson.ejb.SimpleMessenger</remote>  
     <ejb-class>com.jeffhanson.ejb.SimpleMessengerBean</ejb-class>  
     <session-type>Stateless</session-type>  
     <transaction-type>Bean</transaction-type>  
   </session>  
 </enterprise-beans>  
</ejb-jar>

If this seems like a lot of minutiae to fuss with, don't despair; we'll find a helpful utility to ease our job in a moment. In the meantime, let's look at how we ready the environment in which we will deploy our EJB.

Starting the EJB Container

Once you've written and compiled your EJB, you must deploy it into an EJB-container's environment. This typically means installing the EJB into an application server's environment. We will deploy our session bean into the environment of the EJB container that ships with the J2EE reference implementation's server.

To start the J2EE reference implementation's server, run the script file j2ee.bat (j2ee.sh on Unix/Linux), which is found in the <J2EE_HOME>\bin\directory. This will start the server listening to HTTP requests on port 8000. To test the server, point your HTML browser to http://localhost:8000. You should see something that resembles the page in figure 2.

1250_javaserver
Figure 2

If you liked this article, share the love:
Print-Friendly Version Suggest an Article