In this tutorial, you first have to create and implement an EJB 3.0 project. This provides you with the service that will be used by the application client.
The Windows → Open Perspective → Other → Java EE perspective is opened.
You develop the EJB 3.0 classes in an EJB 3.0 project in the Java EE perspective.
1. Choose File → New → Project from the main menu.
2. Expand EJB folder and choose EJB Project. Choose Next.
3. Enter CalculatorServiceEJB in the Project name field. In this field you specify the name of your project.
4. Leave the Default Configuration for SAP Libraries in the Configurations field. The default configurations include the EJB module 5.0 and Java 5.0 project facets.
5. Select Add project to an EAR. Enter CalculatorServiceEAR in the EAR Project Name field. In this field you specify the name of a new enterprise project. This instantly creates the enterprise project. You can use also an already existing enterprise project.
EJB 3.0 Project Settings
6. Choose Finish.
The EJB 3.0 project and its corresponding Enterprise project appear in the Project Explorer.
To use the calculator service from application clients, you must provide a remote interface.
The interface itself is a normal Java interface (also known as POJI – Plain Old Java Interface).
...
1. Copy the Java source below.
2. Expand the project CalculatorServiceEJB.
3. From the context menu of ejbModule folder, choose Paste.
package com.sap.blogs.appclient.calculator.ejb;
/** * Simple calculator with a single operation - addition */ public interface CalculatorRemote { /** * Addition operation * * @param a * the first addend * @param b * the second addend * @return the sum of the two addends */ long add(int a, int b); } |
The implementation of this interface is a simple Java object. The annotation @Stateless means that the EJB bean is stateless and the annotation @Remote indicates that the CalculatorRemote.class is a remote interface for this bean.
...
1. Copy the Java source below.
2. Expand the project CalculatorServiceEJB.
3. From the context menu of ejbModule folder choose Paste.
package com.sap.blogs.appclient.calculator.ejb;
import javax.ejb.Remote; import javax.ejb.Stateless;
@Stateless @Remote(CalculatorRemote.class) public class CalculatorBean { public CalculatorBean() { }
public long add(int a, int b) { return a + b; } } |
You have implemented the session bean class.
Creating and Implementing the Application Client