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

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

    Download:

    Description:

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 describes the EJB 2 sample.

    Steps:

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"?>
<datasources>
    <local-tx-datasource>
        <jndi-name>jdsDB</jndi-name>
        <connection-url>jdbc:borland:dsremote://localhost/c:/Borland/JDataStore7/samples/JDataStore/datastores/employee.jds</connection-url>
        <driver-class>com.borland.datastore.jdbc.DataStoreDriver</driver-class>
        <user-name>SYSDBA</user-name>
        <password>masterkey</password>
    </local-tx-datasource>
</datasources>

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. If the workspace is for this EJB2 sample only, add the jbossall-client.jar in JBOSS_HOME/client. If you plan to also have the EJB3 sample in the workspace, add all JARs matching the pattern *client*.jar, except for jbossws-client.jar, in JBOSS_HOME/client

6. Configure XDoclet. Select Windows | Prefrences.... Select the XDoclet node. Ensure the Enable XDoclet Builder checkbox is selected and that Version is set to 1.2.3. An XDoclet installation is delivered with a JBuilder plugin -- for XDoclet home, specify JB_HOME/jbuilder/eclipse/plugins/com.borland.peloton.j2ee.xdoclet.extension_1.0.0.v20061116_0221.

7. Import the sample project into your 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.

8. 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.codegear.samples.ejb2 project for deployment. Please ensure that you do not select both projects (EJB 2.x and 3.0) for deployment at the same time.

9. 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.

10. 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.

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