Anda di halaman 1dari 5

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:

1. Make a directory to store the database in:

>mkdir \db2j\databases\

2. 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:
3. C:\as51\cloudscape\bin\embedded>echo off
4. ij version 5.1 (c) 2001 IBM Corp.
ij>

5. Type the following line:


6. 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:

1. In the left-hand pane, select Resources and then, under it, JDBC Providers. Click
New.
2. 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:

1. Go into the new Cloudscape entry and select Data Sources. Click New.
2. Give the datasource the name SkatesDataSource, which automatically gives it a
JNDI name: jdbc/SkatesDataSource.
3. Check the box that says Use This Data Source In Container Managed Persistence
(CMP). If you don't, it won't work.
4. 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.
5. 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:

1. From the console, choose Applications and then choose Install New Application.
2. Browse to the Skates.ear file.
3. 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:
o In Deploy EJBs Option, the Database Type is CLOUDSCAPE_V5 and the
Database Schema is SKATES.
o In JNDI Names for Beans, the value for SkatesEntity is
ejb/skates/SkatesEntityHome and the value for SkatesProduct is
ejb/skates/SkatesProductHome.
o In Provide Default Datasource Mapping For Modules Containing 2.0
Entity Beans, the value for Skatesejb.jar is jdbc/SkatesDataSource.
o In Map EJB References To Beans, the value for SkatesProduct and
SkatesEntity is ejb/skates/SkatesEntityHome.
4. Click Finish. You should see the following output:
5. ADMA5016I: Installation of Skates started.
6. ADMA5018I: Starting EJBDeploy on ear
7. c:\as51\wstemp\3433544\upload\skates4.ear..
8. Starting workbench.
9. Creating the project.
10. Building: /skatesejb.
11. Deploying jar skatesejb
12. Creating Top Down Map
13. Generating deployment code
14. Refreshing: /skatesejb/ejbModule.
15. Building: /skatesejb.
16. Invoking RMIC.
17. Generating DDL
18. Generating DDL
19. Writing output file
20. Shutting down workbench.
21. 0 Errors, 0 Warnings, 0 Informational Messages
22. ADMA5007I: EJBDeploy completed on
23. C:\DOCUME~1\paul\LOCALS~1\Temp\app_fa7b3c6751\

24. dpl\dpl_Skates.ear
25. ADMA5005I: Application Skates configured in

26. WebSphere repository


27. ADMA5001I: Application binaries saved in
28. c:\as51\wstemp\3433544\workspace\cells
29. \ZAK-T40\applications\Skates.ear\Skates.ear
30. ADMA5011I: Cleanup of temp dir for app Skates

31. done.
32. ADMA5013I: Application Skates installed
33. successfully.
Application Skates installed successfully.

34. 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:

1. In the Enterprise Applications pane, select the Skates application and click the
Export DDL button.
2. Save the file as skates.ddl in a temporary directory.
3. Back to ij—follow the bold steps shown here:
4. ij version 5.1 (c) 2001 IBM Corp.
5. ij> connect 'jdbc:db2j:c:\db2j\databases\

6. skatesdb';
7. ij> run '\temp\skates.ddl';
8. ij> -- Generated by Relational Schema Center on
9. Tue Feb 03 13:47:07 GMT 2004
10. CREATE SCHEMA SKATES;
11. 0 rows inserted/updated/deleted
12. ij> CREATE TABLE SKATES.SKATESENTITY
13. (PRICE DOUBLE PRECISION NOT NULL,
14. DESCRIPTION VARCHAR(250) NULL,
15. PRODUCTCODE VARCHAR(250) NOT NULL);
16. 0 rows inserted/updated/deleted
17. ij> ALTER TABLE SKATES.SKATESENTITY
18. ADD CONSTRAINT PK_SKATESENTITY PRIMARY KEY

19. (PRODUCTCODE);
20. 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.

Anda mungkin juga menyukai