EJB Development Quickstart with MyEclipse---4
天下维客,你可以修改的网络知识库
Creating a Session EJB - Part-1
EJB development in MyEclipse uses a combination of EJB wizards and integrated XDoclet support. Every EJB consists of 3 basic parts:
- The EJB Remote interface class that declares the business operations that are available to a client
- The EJB implementation class, also known as the bean class, that contains the business logic
- The EJB Home interface class, which controls the bean's life-cycle
The bean class is the primary implementation concern since it provides the EJB's functionality. From the bean class using XDoclet annotations, the bean's Remote and Home interfaces can be automatically generated as well as the EJB's entry within the ejb-jar.xml deployment descriptor. In this 2-part example, we demonstrate the process for creating a stateless session bean known as the Trader EJB. Part-1 focuses on the use of the MyEclipse EJB Creation Wizard and XDoclet support to create a basic deployable Trader EJB. Part-2 will introduce the process for implementation of business services or functions to the Trader EJB.
The example Trader EJB will provide simplified services for the sale and purchase of stocks. Because the scope of this document is a quick introduction to MyEclipse EJB development features, the Trader EJB does not address transactions or integration of enterprise resources such as databases or message queues.
We begin by creating the Trader bean implementation class using the EJB Creation Wizard. Following creation of the Trader bean class, we will demonstrate how to generate the Remote and Home interfaces as well as the ejb-jar.xml entry for the bean.
- From the main workbench window select File > New > Other to open the New Resource Wizard.
- Expand the J2EE > EJB folder and select Session EJB as shown in Figure 5.
Figure 5. New EJB wizard
- Select Next.
This will present a form for the new Session Bean's details (see Figure 6)
- In the Source Folder field, ensure that the source folder within your EJB project is entered correctly since this is where your new EJB class will be placed.
- In the Package field, enter the full package name for the Trader bean class, e.g., com.genuitec.trader.ejb. Use the "Browse..." button to view and select an existing package. If the package does not exist it will be created as part of the completion process.
NOTE: XDoclet's default configuration requires the package name end with '.ejb'. Other package suffixes may be used, but doing so requires updating the project's EJB XDoclet settings manually before generation.
- In the Name field enter TraderBean.
This is the name of the EJB bean implementation class that will be created. The "Bean" suffix is a convention used to identify bean implementation classes. The EJB wizard will remove this suffix when creating the XDoclet tags for related EJB files.
- Choose default values for all remaining fields.
Figure 6. New Session EJB details
- Select Finish
Completing this wizard results in the creation of the TraderBean implementation class. The Java editor will be automatically opened on this class as shown in Figure 7. Note how the EJB Creation Wizard automatically inserted XDoclet EJB tags that define the EJB interface and deployment details.
- Browse the resulting TraderBean.java code in the Java editor.
Figure 7. TraderBean source with XDoclet tags
Revise the TraderBean XDoclet jndi-name tag to be more consistent with examples used in other MyEclipse documentation.
Trader Session bean jndi-name xdoclet tag
- jndi-name = "ejb/com/genuitec/trader/ejb/TraderHome"
</pre>
- Save the TraderBean.java class with your new XDoclet changes (ctl+s or File > Save).





