Show TOC

Developing the EJB ModuleLocate this document in the navigation structure

Prerequisites

The Start of the navigation path Windows Next navigation step Open Perspective Next navigation step Other Next navigation step Java EE End of the navigation path perspective is opened.

Procedure

1. Create the EJB Module Project

You develop the EJB classes in an EJB project.

  1. Choose Start of the navigation path File Next navigation step New Next navigation step Project End of the navigation path from the main menu.

    The New Project dialog opens.

  2. Select Start of the navigation path EJB Next navigation step EJB Project End of the navigation path. Choose Next .

  3. Enter ConverterEJB in the Project name field.

  4. Select Default Configuration for SAP Libraries in the Configuration dropdown list. The default configurations include EJB Module 3.0 and Java 6.0 project facets.

  5. To assign the EJB project to an Enterprise Application project, select the Add project to an EAR checkbox, and enter ConverterEAR in the EAR project name field.

    Note

    The ConverterEAR project is created automatically when you complete the wizard.

  6. Choose Next . Choose Next again.

  7. Deselect the Create an EJB Client JAR module to hold the client interfaces and classes checkbox.

  8. Choose Finish to create your EJB project.

2. Create the Stateless Session Bean

  1. In the Project Explorer , select the ejbModule node of the ConverterEJB project.

  2. In the context menu, choose Start of the navigation path New Next navigation step Other End of the navigation path

    The New dialog opens.

  3. Select Start of the navigation path EJB Next navigation step Session Bean (EJB 3.x) End of the navigation path. Choose Next .

  4. Enter ConverterBean in the Class name field and com.sap.tutorial.javaee in the Java package field.

  5. Select Stateless in the State type dropdown list.

  6. In the Create business interface area, select the Local checkbox and enter com.sap.tutorial.javaee.ConverterLocal as the name. Choose Next .

  7. Select Container in the Transaction type dropdown list.

  8. Choose Finish .

    The Developer Studio creates the ConverterBean and the ConverterLocal interface, and opens the ConverterBean for editing.

  9. Implement the business logic of ConverterBean by entering the following code in its body:

                         private BigDecimal dollarRate = new BigDecimal("1.2");
    
    private BigDecimal euroRate = new BigDecimal("0.83");
    
    public BigDecimal dollarToEuro(BigDecimal dollars) {
    
            BigDecimal result = dollars.multiply(euroRate);
    
            return result.setScale(2, BigDecimal.ROUND_UP);
    
            }
    
    public BigDecimal euroToDollar(BigDecimal euros) {
    
            BigDecimal result = euros.multiply(dollarRate);
    
            return result.setScale(2, BigDecimal.ROUND_UP);
    
            }
                      
  10. To import the additional classes that you refer in your code, choose Start of the navigation path Source Next navigation step Organize Imports End of the navigation path from the main menu.

  11. To add the dollarToEuro business method to the bean's local interface, locate the Outline view and in the context menu of the method, choose Start of the navigation path EJB Methods Next navigation step Add to Local Interfaces End of the navigation path.

    Repeat the same step to add the euroToDollar method to the local interface as well.

  12. Choose Start of the navigation path File Next navigation step Save End of the navigation path from the main menu to save the bean.

Result

You successfully created the EJB module of the Converter application. You can now continue with creating the Web module.

For more information, see Developing the Web Module .