Define a new Geronimo Server Runtime

Specify the installation directory of an existing Geronimo server installation and select Finish.

Start the server in Eclipse from the J2EE perspective.

Creating a EJB Project

Launch Eclipse and right click under the Project Explorer. Select New -> EJB Project.

Name the project as CurrencyConvertEJB and select Next.

!

Use the default values and select Finish.

Right click on ejbModule and select New -> Interface.

Name the package as ejb and the Interface as Converter. Select Finish.

Right click on ejb package and select New -> Class.

Name the class as ConverterBean and select Finish.

Creating a Dynamic Web Project

Launch Eclipse. Select File -> New -> Project.

Select Web -> Dynamic Web Project. Select Next.

On the next screen, name the project as WebEJB.

Select default values for all other fields. Finally select Finish.

Right click on WebContent and select New -> JSP.

Name the JSP index.jsp. Select Next --> Finish.

Right click on Java Resources and select New -> Other.

Select Web -> Servlet. Select Next.

Name the package as webejb and Servlet as ConverterHandler. Select Next -> Finish.

Adding code to EJB Project

Add the following code to the interface Converter.java.

Converter.java

Here the @Remote annotation is used to declare it as a Remote Interface.

Add the following code to the class ConverterBean.java

ConverterBean.java

Here the @Stateless annotation declares the POJO(Plain Old Java Object) as a Stateless session bean.
This complete the EJB code.

Adding code to Web Project

Add the following code to index.jsp.

index.jsp

Add the following code to ConverterHandler servlet.

ConverterHandler.java

The @EJB(name = "ejb/Converter") injects the EJB into the servlet. This completes the code for Web project.

Some more configurations

Modify the deployment plan that is geronimo-web.xml as follows:

geronimo-web.xml

We have added a dependencies element (i.e., <dependencies>) and an ejb reference element (i.e., <ejb-ref>) to geronimo-web.xml. This step is required to make our CurrencyConvertEJB visible to our web application.

Right-click on WebEJB project and select properties. Select Java Build Path -> Projects. Click add and add CurrencyConvertEJB. This is required for the compilation of Client code. This is explained with the following screenshots.

Deploy and Run

Right click on the Geronimo server in the J2EE perspective and select Add and Remove Projects...

There should be 2 projects in your workspace. Select Add All >> and then select Finish.

Launch the browser in Eclipse (use the Globe icon at the top of the Eclipse main window) and run the application using http://localhost:8080/WebEJB/. This will give the following page.