This tutorial walks you through configuring, developing and deploying an enterprise application with Eclipse and Geronimo. To run this tutorial, as a minimum you will be required to have installed the following prerequisite software.
- Sun JDK 5.0+ (J2SE 1.5)
- Eclipse 3.3.1.1 (Eclipse Classic package of Europa distribution), which is platform specific
- Web Tools Platform (WTP) 2.0.1
- Data Tools Platform (DTP) 1.5.1
- Eclipse Modeling Framework (EMF) 2.3.1
- Graphical Editing Framework (GEF) 3.3.1
Details on installing eclipse are provided in the Development environment section. This tutorial is organized in the following sections:
Let us briefly understand this application. This application will take you through creating a simple Stateless Session EJB. Later we will develop a Java Application client to access this EJB. EJB development will make use of annotations which are introduced in Java EE5.
Setting up Eclipse IDE for EJB application development.
- Launch Eclipse and select Window->Open Perspective->Other->JavaEE and select Ok
- Right Click under Project Explorer and create a new EJB project. Mention the fields as shown in the figure. For all the other windows give default values and select Finish.
- Under Project Explorer, Right click on SimpleEJB and create a new package ejb. Mention the fields as shown in the figure. Select Finish.
- Right click on SimpleEJB project under project explorer and select properties.
- Select Java Build Path and select Add External JARs.
- Browse to the directory <GERONIMO_HOME>\repository\org\apache\geronimo\specs\geronimo-ejb_3.0_spec\1.0.1 and select geronimo-ejb_3.0_spec-1.0.1.jar.
- Once done select Ok. You can see the geronimo-ejb_3.0_spec-1.0.1.jar added to the build path. This jar provides the essential classes required for the EJB development.
This completes the setting of Eclispe IDE for EJB application development.
Developing EJB Local interface, EJB Remote Interface and Bean Class
- Right Click on the ejb package and create a new Remote interface CountryCapital as shown in the figure
- Enter the fields as shown in the figure and select Finish.
- Add the following code as shown below
CountryCapital.java
package ejb; import javax.ejb.Remote; @Remote public interface CountryCapital { public String capitalName(String countryName); }
Here @Remote is an annotation used to declare the interface as a Remote Interface.
- Similarly create a Local interface CountryCapitalLocal. Add the following code to the interface
CountryCapitalLocal.java
package ejb; import javax.ejb.Local; @Local public interface CountryCapitalLocal { public String capitalName(String countryName); }
Similarly in this code we have @Local annotation which declares this interface as local.
In remote as well as local interface we have the declaration for only one Business method. So only this method will be visible to the application client. Methods other than capitalName if implemented in the Bean class will be private to Bean class and will not be visible to application client.