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
perspective is opened.You develop the EJB 3.0 classes in an EJB 3.0 project in the Java EE perspective.
Choose
from the main menu.Expand EJB folder and choose EJB Project. Choose Next.
Enter CalculatorServiceEJB in the Project name field. In this field you specify the name of your project.
Leave the Default Configuration for SAP Libraries in the Configurations field. The default configurations include the EJB module 3.0 and Java 6.0 project facets.
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
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).
Copy the Java source below.
Expand the project CalculatorServiceEJB.
From the context menu of ejbModule folder, choose Paste.
Syntax
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 @Statelessmeans that the EJB bean is stateless and the annotation @Remoteindicates that the CalculatorRemote.class is a remote interface for this bean.
Copy the Java source below.
Expand the project CalculatorServiceEJB.
From the context menu of ejbModule folder choose Paste.
Syntax
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.