![]() |
CMP Roster Sample Application |
CMP Roster Application
This document describes how to utilize the CMP Roster sample application in conjunction with the Sun Java (tm) System Application Server 7.This sample application document contains the following sections:
Overview
This sample application is based on the RosterApp application of the J2EETMTutorial. It demonstrates the use of container managed persistence and relationships between the entity beans. The application maintains the team rosters for players in sports leagues. The application has five components.The Roster client is a J2EE application client that accesses the Roster EJB, which is a session EJB. The Roster EJB invokes entity beansTeamEJB, PlayerEJB, and LeagueEJB through their local interface. PlayerEJB represents a player in the sports league, TeamEJB represents a team in the league and the LeagueEJB represents the league. Table 1, Table 2, and Table 3 show the persistent fields of player, league, and team EJB respectively.
Figure 1 below shows the relationship between the entity beans. For more details about Roster application and Container managed persistence, visit the J2EETM tutorial by clicking here.
Figure 1    Relationship between the entity beans
![]()
Compiling and Assembling the Application
To recompile, assemble, and deploy the application, see the Sample Application Build Facility document for details on using a build facility to quickly perform these tasks.To rebuild the entire application from scratch, follow these steps:
Compile and assemble the J2EE application.
Deploy the application.
- Execute the asant command under <install_dir>/samples/ejb/cmp/roster/src
- The default target core is executed to rebuild the .jar and .ear files.
Clean the application project area.
Undeploy the application.
Deploying the Application
A pre-built cmp-roster.ear file is supplied with the application server installation. The pre-built cmp-roster.ear file is an Enterprise Archive (.ear) file that contains, the EJB .jar file, and the Application Client .jar file of the application. Within each file resides the XML deployment descriptor files, application class files, and other content required by the application. You can use the pre-built .ear file to deploy the application. If you want to experience compiling and assembling the application from scratch, follow the instructions in Compiling and Assembling the Application.To deploy the application, the administrative server needs to be running. To start the administrative server if it is not already started:
Execute <install_dir>/domains/domain1/admin-server/bin/startserv
Start->Programs->Sun Java (tm) System Application Server 7->Start Application Server
Select one of the following approaches to deploy the application:
Command Line-based Deployment describes how to manually register the application using a Command Line Interface (CLI). This is the fastest means of deploying the application.
Web-based Deployment describes how to use the web based administration tool to deploy the sample application.
Note GUI-based Assembly Tools does not support assembling CMP 1.1 application from scratch.
Before you deploy the application, you need to start up your PointBase Server. Refer here for how to start up your PointBase Server.
If you want to run the cmp roster sample application with the Oracle database, please refer to (How to run samples with Oracle database server) for configuration steps.
Command Line-based Deployment
Command Line Interface is the fastest means of deploying the application.If you want to deploy through a GUI tool, follow the instructions for GUI Based Deployment.
CLI deployment of the application can be done using either the asant script or using the asadmin command.
The deployment process includes deploying the application .ear file, configuring the database, and registering the required resources to the Sun Java (tm) System application server.
Installation comes with a configured PointBase database.
Deploy the Application Using asant
If you choose to use the PointBase database, execute the following steps:
cd <install_dir>/samples/ejb/cmp/roster/src
Execute the asant deploy command.
- It is an interactive command that may prompt you for the admin-server host, admin-server port, admin user name, admin password, and appserv instance. This also registers the resources to the Sun Java (tm) System application server.
- Now you are ready to run the application (see Running the Sample Application).
Deploy the Application File Using the asadmin Command
cd <install_dir>/samples/ejb/cmp/roster
Now you need to register the resources to the Sun Java (tm) System application server.Execute the command asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> cmp-roster.ear
Proceed to Registering Resources.
The deployment process involves the following operations:
It authenticates against the local application server's administrative server.
If you want to verify the registration of the application, proceed to Verifying Registration.The .ear file is transferred to the administrative server.
The administrative server begins the registration process:
Log in to the web-based administration tool from the browser.
Click Deploy.
Click Browse to locate the cmp-roster.ear file.
Enter cmp-roster in the App Name field.
Click the product link to verify that the application is deployed.
Registering Resources
This section describes how to create resources required for running CMP-Roster application. You do not need to register them separately when you deploy the application using the asant deploy command. However, the resources can be registered as follows:
JDBC Resource and its Associated Connection Pool
Persistence Manager Factory Resource
- asadmin create-jdbc-connection-pool --host <admin host> --port <admin port> --user <user> --password <password> --instance <server instance name> --datasourceclassname <datasource classname> --property User=cmp:Password=cmp:<url-property>="<database jdbc url>" cmp-roster-pool
In case of PointBase, please use DatabaseName as <url-property>. In case of Oracle, please use Url as <url-property>. You will need to escape ":" and "/", in <database jdbc url> . An example of <database jdbc url> is "jdbc\:pointbase\:server\:\/\/localhost\:9092\/sun-appserv-samples".
- asadmin create-jdbc-resource --host <admin host> --port <admin port> --user <user> --password <password> --instance <server instance name> --connectionpoolid cmp-roster-pool jdbc/cmp-roster
Reconfiguring Server Instance
- asadmin create-persistence-resource --host <admin host> --port <admin port> --user <user> --password <password> --instance <server instance name> --jdbcjndiname jdbc/cmp-roster --factoryclass com.sun.jdo.spi.persistence.support.sqlstore.impl.PersistenceManagerFactoryImpl jdo/cmp-roster
Running the Sample Application
The application is run by running the client class, which invokes the EJB. To run the application, go to the following directory:<install-dir>/domains/domain1/<server-instance>/applications/j2ee-apps/cmp-roster_1/
<install_dir>/bin/appclient -client cmp-rosterClient.jar -name RosterClient -textauth
The following output is displayed:
P9 Jan Wesley defender 100.0
P7 Rebecca Struthers midfielder 777.0
P6 Ian Carlyle goalkeeper 555.0
P10 Terry Smithson midfielder 100.0
P8 Anne Anderson forward 65.0T5 Crows Orland
T2 Gophers Manteca
T1 Honey Bees VisaliaP2 Alice Smith defender 505.0
P5 Barney Bold defender 100.0
P25 Frank Fletcher defender 399.0
P9 Jan Wesley defender 100.0
P22 Janice Walker defender 857.0L1 Mountain Soccer
L2 Valley Basketball
Verifying Registration
As an optional step, you can use the Sun Java (tm) System Application Server Administration Tool to verify that the application has been registered. If you do not want to verify that the application has been registered, proceed directly to Running the Sample Application.To verify the registration of the application, execute the iasadmin command to look at applications deployed with a server instance:
You can also execute the iasadmin command to look at application status:
Generating Javadocs
To understand sample application source code better, you can refer to the related javadocs.To generate javadocs run the following command:
After javadocs are generated, you can access them at
<install_dir>/samples/ejb/cmp/roster/javadocs/index.html
Troubleshooting
Make certain that you run the asant undeploy command before redeploying this sample to make sure that all modules are undeployed and the resources are disabled.Although the .ear, context-root and servlet alias names in this sample are all cmp-roster, this is not necessary. The application works as expected if the names of each of these attributes is unique. Rebuild the application after changing the context-root (in application.xml), and the.ear names (in the build.xml), redeploy, and test the sample to confirm.
If you encounter problems when running the application, review the log files at <install-dir>/domains/domain1/<server-instance>/logs/server.log to learn what went wrong.
Copyright © 2002 Sun Microsystems, Inc. All rights reserved.
Last Updated July 12, 2002