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

Figure 4
Now, press the Next button. On the next page:
- Select the Session radio button and the Stateless radio button.
- Select SimpleMessengerBean in the Enterprise Bean Class box, SimpleMessengerHome in the Remote Home Interface box and SimpleMessenger in the Remote Interface box. This should leave you will a page that resembles figure 5.

Figure 5
At this point, press the Next button and then the Finish button on the next page.
Deploying the J2EE Application
Once you've packaged your EJB and added it to the EJBTest application, you can deploy the EJB into the application server. The following steps describe how to do this in deploytool:
- Select the EJBTest application in the navigation pane of deploytool. Select the JNDI Names tab and in the JNDI Name field enter SimpleMessenger and press the Enter key.
- Select the Tools->Deploy . . . menu item. On the first page, make sure that the Object to Deploy is set to EJBTest and the Target Server is set to localhost. Select the Return Client Jar checkbox and then press the Next button.
- On the JNDI Names page, press the Next button and then press the Finish button.
- On the Review page, press the Finish button.
- The deployment process will begin and you will be able to see the progress. When the deployment process is finished, press the OK button.
Now, you can look in the <J2EE_HOME>\public_html directory to find two jar files; EJBTest.jar and EJBTestClient.jar.
Your EJB is now deployed and ready to access from clients. We'll discuss the mechanisms for accessing EJBs from client applications in another article.
Summary
One of the hardest steps for beginning J2EE developers to take is to build their first EJBs. This article attempted to assuage those fears and help you venture into the world of EJB development.
In order to build and run an EJB, you must install a J2EE-compliant EJB container. The reference implementation EJB container can be found in the J2EE development kit from Sun.
Developing an EJB involves most of the same steps and concepts that you have become familiar with when developing plain old Java objects (POJOs), with a few minor differences. The steps involved in developing and deploying an EJB are:
- Write the classes and interfaces for your enterprise bean
- Write a deployment descriptor
- Package the enterprise bean and associated files inside of a jar file
- Deploy the bean
A session bean is composed of a minimum of three mandatory classes/interfaces: the Component interface, the Home interface, and the Enterprise Bean class.
An EJB is compiled in the same manner as a POJO, using the javac compiler, however, for EJBs and EJB clients to communicate, the proxy classes used by the EJB communication protocol (typically RMI) must be generated. These proxy classes are known on the client-side as stubs and on the EJB-side as skeletons.
Once you have 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. 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.
Once you have written your EJB, compiled your EJB you must package and deploy it into an EJB-container's environment. This typically refers to deploying the EJB into an application server's environment. The J2EE reference implementation's deploytool is very useful for creating applications and for packaging and deploying EJBs.