6.7.5: Advanced application assembly and deployment tutorial -- CMP bean application
During this tutorial, you will assemble and deploy a CMP bean application. This
simple J2EE application consists of a single CMP entity bean and
a Java application client. The client creates an EJB, invokes a remote
method, then destroys it. We will start with an EJB 1.0 jar file.
Prerequisites
This tutorial assumes knowledge of the Application assembly tutorial and
Application deployment tutorial, which focused on a Session bean application,
but are also applicable for BMP bean applications. Indeed, many steps of this
tutorial are abbreviated, with links to the steps in the assembly
and deployment tutorials in case you need to refresh your memory.
This tutorial puts more attention on the new steps for CMP bean support,
namely, creating database tables and configuring data sources in the application
server runtime.
You will need a working, supported DB2 or Oracle database
to verify your results using the tutorial steps as they are written.
Of course, you can always use this tutorial to practice the steps,
knowing that your data access is not set up yet.
Overview of steps (60 minutes)
- Obtain the example code
- Start the Application Assembly Tool
- Assemble an EJB module, converting from EJB 1.0 JAR to EJB 1.1
- Assemble an application client module
- Assemble a J2EE application
- Exit the Application Assembly Tool
- Start the server
- Open the administrative console
- Configure a data source
- Install the application
- Regenerate the Web server plug-in configuration
- Stop the application server and start it again
- Create database table or tablespace
- Ensure that the application, application server, and Web server are running
- Test the Java application client
Paths through the tutorial
- Quick path: If your objective is
to practice these steps as quickly as possible, skip the
explanations marked with the
graphic.
- Maximum learning path: If your objective is to understand and explore the
product capabilities, read the
notes and browse the links
they provide to additional documentation.
Start the Application Assembly Tool,
as discussed in the
Application assembly tutorial.
-
On the Welcome to Application Assembly Tool panel:
-
Click the Existing tab.
-
Click Browse next to the File name field.
-
Navigate to the cmp.jar file that you previously downloaded and
select Select.
-
Select OK.
-
Click OK at the "...please specify the dependent classpath..." dialog.
This will convert the EJB
1.0 JAR file into an EJB 1.1 JAR file.
-
Set the global JNDI name of the bean, and bind the data source:
-
In the topology tree, expand the Entity Beans folder.
-
Select the bean labeled:
com_ibm_websphere_gettingstarted_ejbs_SimpleContainerManaged
- Click it to display its properties.
-
Select the Bindings tab.
-
Set the JNDI Name to:
com/ibm/websphere/gettingstarted/ejbs/SimpleContainerManagedHome
You can use a shorter name as long as you guarantee that it
is unique among all installed applications. Using the fully qualified package
name of the bean will accomplish this, usually.
-
Enter Datasource JNDI Name: jdbc/GsDataSource
-
If using an Oracle database, enter the Oracle admin userid and password under
Default
Authorizations (this is not required for DB2).
-
Click Apply.
-
Save the JAR file using File -> Save As... and name it cmp11.jar.
-
Create a new application client using File -> Wizards ->
Create Application Client Wizard.
-
On the Specifying Application Client Module Properties panel:
-
Enter the following:
-
Display Name: SimpleCMP
-
File Name: cmpApp.jar
-
Click Next.
-
Click Add... on the Adding Files panel.
-
Click Browse.
-
Navigate to the client.jar that was previously downloaded, highlight
the file and click Select.
-
Select the com folder (in the right hand pane).
-
Click Add.
-
Click OK.
-
Click Next.
-
On the Specifying Additional Application Client Module Properties panel:
-
Enter cmp11.jar for Classpath.
-
Click Browse next to Main Class field.
-
Expand the topology tree in the left pane as far as it goes and select
clients.
-
Select SimpleContainerManagedClient.class in the right pane.
-
Click OK.
-
Click Next.
-
Click Next on the Choosing Application Client Module Icons panel.
-
Click Add on the Adding EJB References panel:
-
Enter the following:
-
Name: ejb/SimpleCMP
-
Home: com.ibm.websphere.gettingstarted.ejbs.SimpleContainerManagedHome
-
Remote: com.ibm.websphere.gettingstarted.ejbs.SimpleContainerManaged
-
Set Type: Entity
-
Click OK.
-
Verify that your EJB reference is displayed in the EJB References list.
-
Click Next.
-
Click Next on the Adding Resource References panel.
-
Click Finish on the Adding Environment Entries panel.
-
Save the application client jar file using File -> Save As. Name
it cmpApp.jar.
-
Using AAT, create an .ear by clicking File -> Wizards -> Create Application
Wizard.
-
On the Specifying Application Properties panel:
-
Enter the following:
-
Display Name: CmpApp
-
File Name: cmp.ear
-
Click Next.
-
Click Next on the Adding Supplementary Files panel.
-
Click Next on the Choosing Application Icons panel.
-
Click Add... on the Adding EJB Modules panel:
-
Navigate to your cmp11.jar file, highlight the file and click
Open.
-
Click OK in the resulting dialog.
-
Click Next.
-
Click Next on the Adding Web Modules panel.
-
Click Add... on the Adding Application Client Module panel:
-
Navigate to your cmpApp.jar file, hightlight the file and click
Open.
-
Click OK in the resulting dialog.
-
Click Next.
-
Click Finish on the Adding Security Roles panel.
-
Bind the EJB reference:
-
Expand Application Clients
-
Expand SimpleCMP
-
Select EJB References.
-
Select in the right pane the particular reference to your session bean
called ejb/SimpleCMP.
-
Select the Bindings tab.
-
Enter the following for the JNDI name:
com/ibm/websphere/gettingstarted/ejbs/SimpleContainerManagedHome
-
Click Apply.
-
Save the .ear file by clicking File -> Save As. Name it cmp.ear.
-
Generate code for deployment of the .ear file:
-
Select the .ear file by selecting the top entry in the topology tree (named
CmpApp).
-
Right-click it.
-
Select Generate Code for Deployment.
-
In the Generate Code for Deployment panel:
-
Accept the default for the Deployed module location.
-
Select the appropriate database type from the list.
-
Click Generate Now.
-
When the deployment is complete, close this window.
The file containing the code generated for deployment
will be created called Deployed_cmp.ear.
It might take a while to generate the code for deployment. You can proceed
to configure your data source, as described in the next few steps.
The terminology is potentially confusing here. The
file containing the code generated for deployment on the application server is
called the Deployed_filename, although it has not been deployed on the server yet.
At this
point in the application assembly and deployment procedure, the name "Deployed_filename"
is more anticipatory than accurate. However, the name will be suitable shortly. After you deploy
the "Deployed" file, the name will be useful for distinguishing the file from the pre-deployed
version (the one for which you have neither generated code for deployment nor installed
on the application server).
Recall this step from the Application assembly tutorial.
Recall this step from the Application deployment tutorial.
Recall this step from the Application deployment tutorial.
The instructions differ according to whether you are using a DB2
database or Oracle database.
DB2 Database:
-
In the administrative console, update the Db2JdbcDriver:
-
In the topology tree, expand Resources -> JDBC Drivers.
-
Select Db2JdbcDriver.
-
Modify Server Class Path to show the location of the JAR file containing
the DB2 JDBC driver classes (db2java.zip) on your system.
-
NT or Windows 2000: db2java.zip file is located in the sqllib\java
directory
-
Unix: db2java.zip file is located in the sqllib/java12
directory
-
Click OK.
-
Save the configuration by clicking Save.
-
In the administrative console, configure
a new data source:
-
In the tree view, expand Resources -> JDBC Drivers -> Db2JdbcDriver.
-
Select Data Sources.
-
Select New.
-
Enter the following values. (If a field value is not specified, leave the
field blank).
-
Name:
GettingStartedDataSource
-
JNDI Name: jdbc/GsDataSource
-
Database Name: SAMPLEDB
-
Click OK.
-
Save the configuration by clicking Save. Save it under server-cfg.xml
and click OK.
Oracle Database:
-
In the administrative console, create the OracleJdbcDriver:
-
In the topology tree, expand Resources
-
Select JDBC Drivers.
-
Click New.
-
Enter the following:
-
Server Class Path: <oracle JDBC
classes12.zip location>
-
Name:
OracleJdbcDriver
-
Description:
Oracle JDBC Driver
-
Implementation Class: oracle.jdbc.pool.OracleConnectionPoolDataSource
-
Click OK.
-
Save the configuration by clicking Save.
-
In the administrative console, configure
a new data source:
-
In the topology tree, expand Resources -> JDBC Drivers -> OracleJdbcDriver.
-
Select Data Sources.
-
Click New.
-
Enter the following values. (If a field value is not specified, leave the
field blank).
-
Name:
GettingStartedDataSource
-
JNDI Name:
jdbc/GsDataSource
-
Default User ID: <Oracle DB userid>
-
Default Password: <Oracle DB password>
-
Click OK.
-
In the topology tree, expand Resources -> JDBC Drivers -> OracleJdbcDriver
-> DataSources.
-
Select GettingStartedDataSource.
-
Select Property Set at bottom of screen.
-
Select Resource Properties.
-
Click New.
-
Enter the following:
-
Name: URL
-
Type: java.lang.String
-
Value: jdbc:oracle:thin:@<hostname>:1521:<your_Oracle_instance_name>
-
Click OK.
-
Click OK.
-
Click OK.
-
Save the configuration by clicking Save. Save it under server-cfg.xml
and click OK.
Ensure you have finished generating code for deployment, before beginning this step.
- Install the application. Use the application
installer tool.
On Windows NT, use the command:
SEAppInstall -install path/Deployed_cmp.ear -ejbdeploy false
On UNIX systems:
cd product_installation_root/bin
- Invoke SEAppInstall.sh using the syntax for your operating system. Use the arguments:
-install path/Deployed_cmp.ear -ejbdeploy false
In either case, path is the fully qualified path to the .ear file.
-
When prompted for the Default Datasource JNDI Name for the EJB jar, enter
jdbc/GsDataSource
-
When prompted for a database User ID and password:
-
DB2 database: Press enter
-
Oracle database: Enter oracle db userid and password
-
Verify and press Enter if the JNDI Name for the Enterprise Bean
is set to:
com/ibm/websphere/gettingstarted/ejbs/SimpleContainerManagedHome
-
Verify and press Enter if the Datasource JNDI name is set to:
jdbc/GsDataSource
-
When prompted for a database User ID and password:
-
DB2 database: Press enter
-
Oracle database: Enter oracle db userid and password
See the Application deployment tutorial for an example of installation using the Web-based
administrative console instead. You can also view the
administrative
console instructions.
Recall this step from the basic Application deployment tutorial.
Recall this step from the basic Application deployment tutorial.
The instructions differ according to whether you are using a DB2 database
or an Oracle database.
DB2 Database:
-
Open a command window.
-
Type db2cmd (NT/Windows 2000) or db2 (Unix) to start a DB2
command window.
-
If you do not already have a database named SAMPLEDB, you must create one:
-
db2 create database SAMPLEDB
-
Extract the DDL from the deployed jar file:
- In the WebSphere administrative console tree view, select
Nodes -> hostname -> Application Servers
-> Default Server -> EJB Containers
-> Installed EJB modules
- Select the EJB module from list of EJB modules by selecting its check box.
- Click the Export DDL button.
- Click the file from the list of Table.DDL files to download it.
- Click OK.
-
Create the table:
-
db2 connect to SAMPLEDB
-
db2 -t -f META-INF\Table.ddl
A table named COM_IBM_WEBSPHERE_GETTINGSTAR1 will be added to the SAMPLEDB
database.
-
Exit the db2 command window.
Oracle Database:
-
Open a command window.
-
Extract the DDL from the deployed jar file:
-
jar -xvf %was_home%\installedApps\Deployed_cmp.ear\cmp11.jar META-INF\Table.ddl
-
Create the tablespaces:
-
svrmgrl
-
connect <oracle db userid>/<oracle db password>
-
@META-INF\Table.ddl
A tablespace named COM_IBM_WEBSPHERE_GETTINGSTAR1 will be added database.
-
Exit the oracle command window.
Recall learning this step in the Application testing tutorial.
- Open a system command prompt.
- Change directory to:
product_installation_root/bin
- Enter the command:
launchClient ../temp/tutorial/cmp/Deployed_cmp.ear
(Remember, on Windows systems, the forward slashes should be backslashes).
What's next?
Proceed to the Application removal and cleanup tutorial
if you would like to uninstall the applications that you introduced into the server
runtime during the tutorial.