EJB3.0 Stateless Session Beans with Glassfish 3.1.1 (Open Source Edition)

EJB is not difficult. Well, not as much if you do not have a good grasp of Servlet/JSP architecture and great deal of Java web technologies experience.  Almost the same stuff can be seen in the EJB world Рcontainer, container-managed objects, life-cycles, container callback methods, deploy-time descriptors, and etc.

So, if you are pretty familiar with the basics, EJB is easier than you think. EJB2.x or EJB3.x? It does not really matter.

Software applications used

  • Glassfish 3.1.1 – Open Source Edition
  • JDK1.6 update 21
  • Eclipse Ganymede
  • Windows XP

First, download a Glassfish installer from http://glassfish.java.net/, run it, and use default settings during installation. Then, create an Java project in Eclipse and reference the javax.ejb.jar (<GLASSFISH_HOME>/glassfish/module) library.


Eclipse Project

The client

The Remote Interface

The Local Interface

The Stateless Session bean

Then, build the codes in Eclipse and jar them up – including the client. This will make the testing the client easier but we need to specify the Main-Class during the creation of the jar file. Jar command:


Jar file

The Manifest.txt contains the following (plus a carriage return):

Finally, deploy the jar via GlassFish Server Administration Console.


Deployed EJB3.0 Session Bean

Now, let us test the client. Copy the jar file to the directory shown in the image just below and use appclient.bat.


Test EJB client using appclient.bat

Karl San Gabriel

Karl San Gabriel

Java and Enterprise Technologies Expert