JBuilder 2007 Sample: EJB 3.x application with JBoss 4.0.5

Abstract: A simple example using 3.x EJBs, and a standalone Java client



This sample uses the JDataStore 7 sample database, employee.jds and the JBoss 4.0.5 application server. The sample contains 2 CMP entity beans, Employee and Project with a many-many relationship. These beans map to the EMPLOYEE and PROJECT tables in the JDataStore database. The Employee bean contains a findAll query that returns all rows in the EMPLOYEE table. The session bean 'EmployeeSession' contains a business method that invokes the finder on the Employee entity bean. The CMR field 'projects' in the Employee bean is used to retrieve all assigned projects for each employee. The result set is returned from the business method as a String. The standalone client 'Client' invokes the business method in the session bean. There are 2 versions of this sample, one for EJB 2.x and one for EJB 3.0. This document discusses the EJB 3 sample.


1. JBoss 4.0.5 must be installed and setup for JBuilder in order to build and deploy this sample. You can choose to install JBoss along with JBuilder 2007. The application server installed during the JBuilder 2007 install process can be found under the thirdparty directory under your JBuilder root directory (JB_HOME/thirdparty/jboss-4.0.5.GA). If you have not installed JBoss along with JBuilder 2007, install it separately.

2. This sample uses the JDataStore 7 sample database employee.jds that ships with JDataStore 7. You can install JDataStore 7 along with JBuilder 2007. The database is located in directory JDS_HOME/samples/JDataStore/datastores/employee.jds. You will need to configure a JBoss datasource for JDataStore. Create a file named jdatastore-ds.xml and copy the following XML snippet into the file. Place the file in the JBOSS_HOME/server/default/deploy directory. Copy the JDataStore JDBC driver (JDS_HOME/lib/jdsserver.jar) to JBOSS_HOME/server/default/lib.

<?xml version="1.0" encoding="UTF-8"?>

3. Start the JDataStore server using JDS_HOME/bin/jdsserver.exe

4. Launch JBuilder in a new workspace. Select Window | Preferences.... Expand the Server node and click on Installed Runtimes. Click on Add. Expand the JBoss node and select JBoss v4.0 for EJB 3.0 (Borland). Click Next and set the application server home directory.

5. Create a client library to run the standalone Java client. Select Window | Preferences.... Expand the Java node. Expand the Build Path node. Click on User Libraries. Click on New. Enter name JBoss Client. Click OK. Select the library, click on Add Jars and add all JARs matching the pattern *client*.jar, except for jbossws-client.jar, in JBOSS_HOME/client.

6. Import sample projects into workspace. Copy the zip file containing this project to your hard drive. Select File | Import. Import the project into JBuilder (File | Import | Existing Projects into Workspace | Next | Select Archive File | Browse -- select the .zip file). Select Project and click Build Automatically to turn off automatic builds for workspace. Select Project | Build All. The projects should be built successfully without any errors.

7. Switch to the modeling perspective. Click on the Servers view. Right click and select New | Server. Expand the JBoss node and select JBoss v4.0 for EJB 3.0 (Borland). Click Next. Change settings as per your server configuration. Accept all defaults, if you have not changed any settings in JBoss. Select the com.borland.samples.ejb3 project for deployment. Please ensure that you do not select both projects (EJB 2.x and 3.0) for deployment at the same time.

8. To open the EJB diagram, click on the Model Navigator tab in the Modeling Perspective. Expand the project node. Double click on the package 'com' to open the diagram. Double click on the package codegear to open the package diagram. Repeat the process until you reach the 'ejb' package.

9. Launch the application server by right clicking on the server in the Servers view and selecting Start. The server should start with the EJB sample deployed successfully.

10. Launch the client by selecting  Run | Run.... Expand the Java application node and select the EJB 3 Client Run configuration. The client should print out a list of employees and associated projects.