Deploying an EJB Application
(Page 1 of 4 )
This article shows you how to deploy an EJB application, and more. Picking up where the previous article left off, it is the third of three parts. It is excerpted from chapter 7 of the book
Building Web Services with Java: Making sense of XML, SOAP, WSDL, and UDDI, written by Steve Graham et al. (Sams; ISBN: 0672326418).
WebSphere Deployment Process
In order to deploy this as an EJB application, you need to go through a server-specific deployment process that configures the application to run on a given server. As an example, we'll show you how to deploy this EAR file into WebSphere Application Server. However, the sample code is pure J2EE and so will deploy in any EJB2.0 server.
The process followed in this book is simple; we use command-line tools and the Web console. However, as of this version of WebSphere, a new tool called the Application Server Toolkit (ASTK) is available, which makes the procedure considerably easier.
If you have a different J2EE application server, then follow the guidelines appropriate to that server. The deployment options should be standard and easily managed. For more information, you may wish to see the settings that were configured in WebSphere to deploy the application.
A Simple View of the Deployment Process - The next stages may seem complicated, so here's a heads-up of what we're about to do. You can think of this process as wiring everything together:1. Create a database.
2. Wire that to your application server.
3. Wire the entity bean to the database.
4. Wire the session bean to the entity bean.
5. Switch to Axis and create a WSDL file.
6. Wire the Axis service to the session bean.
Once you've completed these steps, everything should work!
In order to deploy into WebSphere, the Axis application must be modified to be a Servlet 2.3 application (the default was 2.2). Doing so involves changing the !DOCTYPE line of the web.xml file as follows:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
This is the only change required to convert it into a Servlet 2.3 Web application.
EJB Deployment
The major item that's completely server specific for this application is the database that backs up the CMP entity bean. In order to enable it, you need to configure a new database in your database server and create a new datasource in your application server to manage connections to it.
WebSphere comes with a lightweight database system called Cloudscape. The first step is to create a new Cloudscape database in which to store the data from the CMP entity bean in. Follow these steps:
Make a directory to store the database in:
>mkdir \db2j\databases\
Create a database. The easiest way to do so is to use the supplied ij utility. It's in the <websphere>\cloudscape\bin\embedded directory. Start it with the ij command line:
C:\as51\cloudscape\bin\embedded>echo off
ij version 5.1 (c) 2001 IBM Corp.
ij>
Type the following line:
connect 'jdbc:db2j:c:\db2j\databases\
skatesdb;create=true';
Then type
exit;
to quit ij. You'll need to come back to ij later to create the table.
You should now have a local database. The next step is to link it to WebSphere by creating a datasource: the virtualization of the database that allows your code to be linked to the database without your having coded any DB-specific commands in the application.
To create a new datasource in WebSphere, you must first create a JDBC Provider. This is a configuration that tells WebSphere about a given JDBC database and classes. Luckily, Cloudscape is preconfigured into WebSphere, so you don't need to do much (see Figure 7.3).
Creating a default Cloudscape provider works just fine:
In the left-hand pane, select Resources and then, under it, JDBC Providers. Click New.
Select Cloudscape JDBC Provider.
Now that you have a JDBC Provider, you can add a datasource. This tells WebSphere about the newly created SKATESDB database. Follow these steps:
Go into the new Cloudscape entry and select Data Sources. Click New.
Give the datasource the name SkatesDataSource, which automatically gives it a JNDI name: jdbc/SkatesDataSource.
Check the box that says Use This Data Source In Container Managed Persistence (CMP). If you don't, it won't work.
Go into Custom Properties at the bottom of the configuration page for SkatesDataSource. In the custom entry databaseName, change the value to match the new directory you created earlier: c:/db2j/databases/SkatesDB.
Save your configuration. (For more information, see the WebSphere docs: http://publib.boulder.ibm.com/ infocenter/wsphelp/topic/com.ibm. websphere.nd.doc/info/ae/ae/tdat ccrtpds.html.)

Figure 7.3 The WebSphere Admin console
Now that your database resource is defined, you can configure and deploy the application:
From the console, choose Applications and then choose Install New Application.
Browse to the Skates.ear file.
The wizard will take you through a number of steps; in most of them, you can accept the default values. The ones you need to change are listed here:
In Deploy EJBs Option, the Database Type is CLOUDSCAPE_V5 and the Database Schema is SKATES.
In JNDI Names for Beans, the value for SkatesEntity is ejb/skates/SkatesEntityHome and the value for SkatesProduct is ejb/skates/SkatesProductHome.
In Provide Default Datasource Mapping For Modules Containing 2.0 Entity Beans, the value for Skatesejb.jar is jdbc/SkatesDataSource.
In Map EJB References To Beans, the value for SkatesProduct and SkatesEntity is ejb/skates/SkatesEntityHome.
Click Finish. You should see the following output:
ADMA5016I: Installation of Skates started.
ADMA5018I: Starting EJBDeploy on ear
c:\as51\wstemp\3433544\upload\skates4.ear..
Starting workbench.
Creating the project.
Building: /skatesejb.
Deploying jar skatesejb
Creating Top Down Map
Generating deployment code
Refreshing: /skatesejb/ejbModule.
Building: /skatesejb.
Invoking RMIC.
Generating DDL
Generating DDL
Writing output file
Shutting down workbench.
0 Errors, 0 Warnings, 0 Informational Messages
ADMA5007I: EJBDeploy completed on
C:\DOCUME~1\paul\LOCALS~1\Temp\app_fa7b3c6751\
dpl\dpl_Skates.ear
ADMA5005I: Application Skates configured in
WebSphere repository
ADMA5001I: Application binaries saved in
c:\as51\wstemp\3433544\workspace\cells
\ZAK-T40\applications\Skates.ear\Skates.ear
ADMA5011I: Cleanup of temp dir for app Skates
done.
ADMA5013I: Application Skates installed
successfully.
Application Skates installed successfully.
Choose Save To The Master Configuration and restart the server.
This process creates the DDL database table definition SQL, which you'll use to create the Cloudscape tables:
In the Enterprise Applications pane, select the Skates application and click the Export DDL button.
Save the file as skates.ddl in a temporary directory.
Back to ij—follow the bold steps shown here:
ij version 5.1 (c) 2001 IBM Corp.
ij> connect 'jdbc:db2j:c:\db2j\databases\
skatesdb';
ij> run '\temp\skates.ddl';
ij> -- Generated by Relational Schema Center on
Tue Feb 03 13:47:07 GMT 2004
CREATE SCHEMA SKATES;
0 rows inserted/updated/deleted
ij> CREATE TABLE SKATES.SKATESENTITY
(PRICE DOUBLE PRECISION NOT NULL,
DESCRIPTION VARCHAR(250) NULL,
PRODUCTCODE VARCHAR(250) NOT NULL);
0 rows inserted/updated/deleted
ij> ALTER TABLE SKATES.SKATESENTITY
ADD CONSTRAINT PK_SKATESENTITY PRIMARY KEY
(PRODUCTCODE);
0 rows inserted/updated/deleted
ij>
Once you have Axis and SkatesEJB deployed and running in a server, you need to test that Axis is running in the new server. You can use the Enterprise Applications panel to test by browsing http://server:port/axis and seeing whether you get an Axis Web page (see Figure 7.4).
Click the Validate link and receive Axis happiness, as shown in Figure 7.5.
If both of those steps work, then the next task is to create a DD and deploy the SkatesService service.
Next: Configuring Axis to Invoke the SkatesService Session Bean >>
More Web Services Articles
More By Sams Publishing
|
This article is excerpted from chapter 7 of the book Building Web Services with Java: Making sense of XML, SOAP, WSDL, and UDDI, written by Steve Graham et al. (Sams; ISBN: 0672326418). Check it out today at your favorite bookstore. Buy this book now.
|
|