Creating the HelloWorld EJB

Context

In the HelloWorldEJB project, you create a session EJB, which provides the business logic of the Web service.

Procedure

  1. In the Project Explorer , choose the HelloWorldEJB project, and then choose Start of the navigation pathFile Next navigation step New Next navigation step OtherEnd of the navigation path.
  2. In the list of wizards, choose Start of the navigation pathEJB Next navigation step Session BeanEnd of the navigation path, and then choose Next .
  3. In the Java package field, enter com.sap.tutorial.helloworld .
  4. In the Class name field, enter HelloBean .

    Make sure that the EJB project field contains the HelloWorldEJB project.

  5. In the Create Business Interface area, select both Remote and Local , and then choose Finish .

    The system opens the created EJB session bean for editing.

  6. Update the source code as shown in the sample below. The code shows the implementation of a Java class that returns a string: Hello, <name> .

    The value of <name> is provided by user input.

    
    package com.sap.tutorial.helloworld;
    import javax.ejb.Stateless;
     
    @Stateless(name="HelloBean")
    public class HelloBean 
    implements HelloBeanRemote, HelloBeanLocal {
       
    private String message = "Hello, ";
       
    public String sayHello(String name) {
       
    return message + name + ".";
       }
    }
                   
  7. In the Project Explorer , expand the HelloWorldEJB project, and then choose Start of the navigation pathejbModule Next navigation step com.sap.tutorial.helloworld Next navigation step HelloBean.java Next navigation step HelloBean Next navigation step sayHello(String)End of the navigation path.
  8. Right-click sayHello(String) , and then choose Start of the navigation pathEJB Methods Next navigation step Add to Local and Remote InterfacesEnd of the navigation path.
  9. Save your changes.

Results

The HelloBean.java class appears in the HelloWorldEJB project. The sayHello class is added to the local and remote Java interfaces.

Next Steps

Next step : Exposing the EJB as a Web Service