Show TOC

Procedure documentationCreating the HelloWorld EJB Locate this document in the navigation structure

 

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   File   New   Other  .

  2. In the list of wizards, choose   EJB   Session Bean  , and then choose Next.

  3. In the Class Name field, enter HelloBean.

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

  4. In the Java Package field, enter com.sap.tutorial.helloworld.

  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.

    Syntax Syntax

    1. 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 + ".";
         }
      }
    End of the code.
  7. In the Project Explorer, expand the HelloWorldEJB project, and then choose   ejbModule   com.sap.tutorial.helloworld   HelloBean.java   HelloBean   sayHello(String)  .

  8. Right-click sayHello(String), and then choose   EJB Methods   Add to Local and Remote Interfaces  .

  9. Save your changes.

Result

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

Next step: Exposing the EJB as a Web Service