Chapter 4.  Developing Your First Enterprise Beans

Choosing and Setting Up an EJB Server

One of the most important features of EJB is that enterprise beans work with containers from different vendors. However, that doesn’t mean that selecting a server and installing your enterprise beans on that server are trivial processes.[18]

The EJB server you choose should provide a utility for deploying an enterprise bean. It doesn’t matter whether the utility is command-line oriented or graphical, as long as it does the job. The deployment utility should allow you to work with prepackaged enterprise beans, i.e., enterprise beans that have already been developed and archived in a JAR file. Finally, the EJB server should support an SQL-standard relational database that is accessible using JDBC. For the database, you should have privileges sufficient for creating and modifying a few simple tables in addition to normal read, update, and delete capabilities. If you have chosen an EJB server that does not support an SQL-standard relational database, you may need to modify the examples to work with the product you are using.

This book does not say very much about how to install and deploy enterprise beans. That task is largely server-dependent. I’ll provide some general ideas about how to organize JAR files and create deployment descriptors, but for a complete description of the deployment process, you’ll have to refer to your vendor’s documentation or look at the workbook for your vendor.

This chapter provides you with your first opportunities to use a workbook. Throughout the rest of this book, you will see callouts that direct you to exercises in the workbook. A callout will look something like the following:

Choosing and Setting Up an EJB ServerPlease refer to Workbook Exercise 4.2, A Simple Session Bean. This workbook is available free, in PDF format, at

As was mentioned in the Preface, the workbooks can be downloaded in PDF format from or—some workbooks may even be available in paper book form and can be ordered directly from

Setting Up Your Java IDE

To get the most from this chapter, it helps to have an IDE that has a debugger and allows you to add Java files to its environment. Several Java IDEs—such as WebGain’s Visual Cafe, IBM’s VisualAge, Borland’s JBuilder, and Sun’s Forte—fulfill this simple requirement. Some EJB products, such as IBM’s WebSphere, are tightly coupled with an IDE that makes life a lot easier when it comes to writing, deploying, and debugging your applications.

Once you have an IDE set up, you need to include the Enterprise JavaBeans package, javax.ejb. You also need the JNDI packages, including javax.naming,, and javax.naming.spi. In addition, you will need the javax.rmi and javax.jms packages. All these packages can be downloaded from Sun’s Java site ( in the form of ZIP or JAR files. They may also be accessible in the subdirectories of your EJB server, normally under the lib directory.

[18] To help you work with different vendors’ products, I have created free workbooks for specific EJB servers. See the Preface for more information about these workbooks and how to obtain them.

Get Enterprise JavaBeans, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.