JavaTM Message Service Tutorial
Tutorial Homepage | TOC | Prev | Next | Index

9    A J2EETM Application that Uses the JMS API with an Entity Bean

This chapter explains how to write, compile, package, deploy, and run a J2EETM application that uses the JMS API with an entity bean. The application uses the following components:

The chapter covers the following topics:

If you downloaded the tutorial examples as described in the preface, you will find the source code files for this chapter in jms_tutorial/examples/client_mdb_ent (on UNIX® systems) or jms_tutorial\examples\client_mdb_ent (on Microsoft Windows systems). The directory ear_files in the examples directory contains a built application called SampleNewHireApp.ear. If you run into difficulty at any time, you can open this file in the deploytool and compare that file to your own version.

9.1   Overview of the Human Resources Application

This application simulates, in a simplified way, the work flow of a company's human resources (HR) department when it processes a new hire. This application also demonstrates how to use the J2EE platform to accomplish a task that many JMS client applications perform.

A JMS client must often wait for several messages from various sources. It then uses the information in all these messages to assemble a message that it then sends to another destination. (The common term for this process is joining messages.) Such a task must be transactional, with all the receives and the send as a single transaction. If all the messages are not received successfully, the transaction can be rolled back. For a client example that illustrates this task, see Section A.2, "Transactions."

A message-driven bean can process only one message at a time in a transaction. To provide the ability to join messages, a J2EE application can have the message-driven bean store the interim information in an entity bean. The entity bean can then determine whether all the information has been received; when it has, the entity bean can create and send the message to the other destination. Once it has completed its task, the entity bean can be removed.

The basic steps of the application are as follows.

  1. The HR department's application client generates an employee ID for each new hire and then publishes a message containing the new hire's name and employee ID. The client then creates a temporary queue with a message listener that waits for a reply to the message.
  2. Two message-driven beans process each message: One bean assigns the new hire's office number, and one bean assigns the new hire's equipment. The first bean to process the message creates an entity bean to store the information it has generated. The second bean locates the existing entity bean and adds its information.
  3. When both the office and the equipment have been assigned, the entity bean sends to the reply queue a message describing the assignments. The application client's message listener retrieves the information. The entity bean also sends to a Schedule queue a message that contains a reference to the entity bean.
  4. The Schedule message-driven bean receives the message from the entity bean. This message serves as a notification that the entity bean has finished joining all messages. The message contains the primary key to look up the entity bean instance that aggregates the data of the joined messages. The message-driven bean accesses information from the entity bean to complete its task and then removes the entity bean instance.

Figure 9.1 illustrates the structure of this application. An actual HR application would have more components, of course; other beans could set up payroll and benefits records, schedule orientation, and so on.

Figure 9.1   A J2EE Application: Client to Message-Driven Beans to Entity Beans

9.2   Writing and Compiling the Application Components

Writing and compiling the components of the application involve

9.2.1   Coding the Application Client: HumanResourceClient.java

The application client program, HumanResourceClient.java, performs the following steps:

  1. Uses the JavaTM Naming and Directory InterfaceTM (JNDI) API naming context java:comp/env to look up a TopicConnectionFactory, a QueueConnectionFactory, and a topic
  2. Creates a TemporaryQueue to receive notification of processing that occurs, based on new-hire events it has published
  3. Creates a QueueReceiver for the TemporaryQueue, sets the QueueReceiver's message listener, and starts the connection
  4. Creates a TopicPublisher and a MapMessage
  5. Creates five new employees with randomly generated names, positions, and ID numbers (in sequence) and publishes five messages containing this information

The message listener, HRListener, waits for messages that contain the assigned office and equipment for each employee. When a message arrives, the message listener displays the information received and checks to see whether all five messages have arrived yet. When they have, the message listener notifies the main program, which then exits.

9.2.2   Coding the Message-Driven Beans

This example uses three message-driven beans. Two of them, ReserveEquipmentMsgBean.java and ReserveOfficeMsgBean.java, take the following steps.

  1. The ejbCreate method gets a handle to the home interface of the entity bean.
  2. The onMessage method retrieves the information in the message. The ReserveEquipmentMsgBean's onMessage method chooses equipment, based on the new hire's position; the ReserveOfficeMsgBean's onMessage method randomly generates an office number.
  3. After a slight delay to simulate real-world processing hitches, the onMessage method calls a helper method, compose.
  4. The compose method either creates or finds, by primary key, the SetupOffice entity bean and uses it to store the equipment or the office information in the database.

The third message-driven bean, ScheduleMsgBean.java, is notified when the SetupOfficeBean entity bean instance has aggregated data from all messages needed to set up an office. The message contains the primary key to look up the correct composite entity bean instance. The ScheduleMsgBean's onMessage method then schedules the office setup, based on the information aggregated in the entity bean instance. Finally, the ScheduleMsgBean's onMessage method removes the entity bean instance.

9.2.3   Coding the Entity Bean

The SetupOffice bean is an entity bean that uses a local interface. The local interface allows the entity bean and the message-driven beans to be packaged in the same EJBTM JAR file for maximum efficiency. The entity bean has these components:

9.2.3.1   The Local Home Interface: SetupOfficeLocalHome.java

The local home interface source file is SetupOfficeLocalHome.java. It declares the create method, called createLocal for a bean that uses a local interface, and one finder method, findByPrimaryKey.

9.2.3.2   The Local Interface: SetupOffice.java

The local interface, SetupOffice.java, declares several business methods that get and manipulate new-hire data.

9.2.3.3   The Bean Class: SetupOfficeBean.java

The bean class, SetupOfficeBean.java, implements the business methods and their helper method, checkIfSetupComplete. The bean class also implements the required methods ejbCreateLocal, ejbPostCreateLocal, setEntityContext, unsetEntityContext, ejbRemove, ejbActivate, ejbPassivate, ejbLoad, and ejbStore. The ejbFindByPrimaryKey method is generated automatically.

The only methods called by the message-driven beans are the business methods declared in the local interface, the findByPrimaryKey method, and the createLocal method. The entity bean uses container-managed persistence, so all database calls are generated automatically.

9.2.4   Compiling the Source Files

To compile all the files in the application, go to the directory client_mdb_ent and do the following.

  1. Make sure that you have set the environment variables shown in Table 4.1: JAVA_HOME, J2EE_HOME, CLASSPATH, and PATH.
  2. At a command line prompt, compile the source files:
    javac *.java
    

9.3   Creating and Packaging the Application

Creating and packaging this application involve several steps:

  1. Starting the J2EE server and the deploytool*
  2. Creating a queue
  3. Starting the Cloudscape database server
  4. Creating the J2EE application
  5. Packaging the application client
  6. Packaging the Equipment message-driven bean
  7. Packaging the Office message-driven bean
  8. Packaging the Schedule message-driven bean
  9. Packaging the entity bean
  10. Specifying the entity bean deployment settings
  11. Specifying the JNDI API names ("JNDI names")

Step 1, marked with an asterisk (*), is not needed if the server and the deploytool are running.

9.3.1   Starting the J2EE Server and the Deploytool

Before you can create and package the application, you must start the J2EE server and the deploytool. Follow these steps.

  1. At the command line prompt, start the J2EE server:
    j2ee -verbose
    

    Wait until the server displays the message "J2EE server startup complete."

    (To stop the server, type j2ee -stop.)

  2. At another command line prompt, start the deploytool:
    deploytool
    

    (To access the tool's context-sensitive help, press F1.)

9.3.2   Creating a Queue

For this application, you publish messages by using one of the topics that the J2EE server creates automatically. You create a queue to process the notification that the composite entity bean has aggregated the group of related messages that it was joining. Follow these steps.

  1. In the deploytool, select the Tools menu.
  2. From the Tools menu, choose Server Configuration.
  3. Under the JMS folder, select Destinations.
  4. In the JMS Queue Destinations area, click Add.
  5. In the text field, enter jms/ScheduleQueue.
  6. Click OK.
  7. If you wish, you can verify that the queue was created:
    j2eeadmin -listJmsDestination
    

9.3.3   Starting the Cloudscape Database Server

The Cloudscape software is included with the J2EE SDK download bundle. You may also run this example with databases provided by other vendors.

From the command line prompt, run the Cloudscape database server:

cloudscape -start

9.3.4   Creating the J2EE Application

Create a new J2EE application, called NewHireApp, and store it in the file named NewHireApp.ear. Follow these steps.

  1. In the deploytool, select the File menu.
  2. From the File menu, choose New -> Application.
  3. Click Browse next to the Application File Name field, and use the file chooser to locate the directory client_mdb_ent.
  4. In the File Name field, enter NewHireApp.
  5. Click New Application.
  6. Click OK.

A diamond icon labeled NewHireApp appears in the tree view on the left side of the deploytool window. The full path name of NewHireApp.ear appears in the General tabbed pane on the right side.

9.3.5   Packaging the Application Client

In this section, you will run the New Application Client Wizard of the deploytool to package the application client. To start the New Application Client Wizard, follow these steps.

  1. In the tree view, select NewHireApp.
  2. From the File menu, choose New -> Application Client. The wizard displays a series of dialog boxes.
9.3.5.1   Introduction Dialog Box

Click Next.

9.3.5.2   JAR File Contents Dialog Box
  1. In the combo box labeled Create Archive Within Application, select NewHireApp.
  2. Click the Edit button next to the Contents text area.
  3. In the dialog box Edit Contents of <Application Client>, choose the client_mdb_ent directory. If the directory is not already in the Starting Directory field, type it in the field, or locate it by browsing through the Available Files tree.
  4. Select HumanResourceClient.class and HumanResourceClient$HRListener.class from the Available Files tree area and click Add.
  5. Click OK.
  6. Click Next.
9.3.5.3   General Dialog Box
  1. In the Application Client combo box, select HumanResourceClient in the Main Class field, and enter HumanResourceClient in the Display Name field.
  2. In the Callback Handler Class combo box, verify that container-managed authentication is selected.
  3. Click Next.
9.3.5.4   Environment Entries Dialog Box

Click Next.

9.3.5.5   Enterprise Bean References Dialog Box

Click Next.

9.3.5.6   Resource References Dialog Box

In this dialog box, you associate the JNDI API context names for the connection factories in the HumanResourceClient.java source file with the names of the TopicConnectionFactory and the QueueConnectionFactory. You also specify container authentication for the connection factory resources, defining the user name and the password that the user must enter in order to be able to create a connection. Follow these steps.

  1. Click Add.
  2. In the Coded Name field, enter jms/TopicConnectionFactory--the logical name referenced by HumanResourceClient.
  3. In the Type field, select javax.jms.TopicConnectionFactory.
  4. In the Authentication field, select Container.
  5. In the Sharable field, make sure that the checkbox is selected. This allows the container to optimize connections.
  6. In the JNDI Name field, enter jms/TopicConnectionFactory.
  7. In the User Name field, enter j2ee.
  8. In the Password field, enter j2ee.
  9. Click Add.
  10. In the Coded Name field, enter jms/QueueConnectionFactory--the logical name referenced by HumanResourceClient.
  11. In the Type field, select javax.jms.QueueConnectionFactory.
  12. In the Authentication field, select Container.
  13. In the Sharable field, make sure that the checkbox is selected.
  14. In the JNDI Name field, enter jms/QueueConnectionFactory.
  15. In the User Name field, enter j2ee. (If the user name and the password appear to be filled in already, make sure that you follow the instructions at the end of Section 9.3.5.8 after you exit the Wizard.)
  16. In the Password field, enter j2ee.
  17. Click Next.
9.3.5.7   JMS Destination References Dialog Box

In this dialog box, you associate the JNDI API context name for the topic in the HumanResourceClient.java source file with the name of the default topic. You do not specify the queue, because it is a temporary queue created programmatically rather than administratively and does not have to be specified in the deployment descriptor. Follow these steps.

  1. Click Add.
  2. In the Coded Name field, enter jms/NewHireTopic--the logical name for the publisher topic referenced by HumanResourceClient.
  3. In the Type field, select javax.jms.Topic.
  4. In the JNDI Name field, enter jms/Topic (the default topic).
  5. Click Next.
9.3.5.8   Review Settings Dialog Box
  1. Check the settings for the deployment descriptor.
  2. Click Finish.

After you exit the Wizard, do the following.

  1. Select the HumanResourceClient node in the tree.
  2. Select the Resource Refs tabbed pane.
  3. Select the second entry in the table, jms/QueueConnectionFactory.
  4. See whether the User Name and Password fields are filled in. If they are blank, enter j2ee in each field.
  5. Choose Save from the File menu to save the application.

9.3.6   Packaging the Equipment Message-Driven Bean

In this section, you will run the New Enterprise Bean Wizard of the deploytool to package the first message-driven bean. To start the New Enterprise Bean Wizard, follow these steps.

  1. In the tree view, select NewHireApp.
  2. From the File menu, choose New -> Enterprise Bean. The wizard displays a series of dialog boxes.
9.3.6.1   Introduction Dialog Box

Click Next.

9.3.6.2   EJB JAR Dialog Box
  1. In the combo box labeled JAR File Location, verify that Create New JAR File in Application and NewHireApp are selected.
  2. In the JAR Display Name field, verify that the name is Ejb1, the default display name. Representing the enterprise bean JAR file that contains the bean, this name will be displayed in the tree view.
  3. Click the Edit button next to the Contents text area.
  4. In the dialog box Edit Contents of Ejb1, choose the client_mdb_ent directory. If the directory is not already in the Starting Directory field, type it in the field, or locate it by browsing through the Available Files tree.
  5. Select the ReserveEquipmentMsgBean.class file from the Available Files tree area and click Add.
  6. Click OK.
  7. Click Next.
9.3.6.3   General Dialog Box
  1. In the Bean Type combo box, select the Message-Driven radio button.
  2. Under Enterprise Bean Class, select ReserveEquipmentMsgBean.
  3. In the Enterprise Bean Name field, enter EquipmentMDB.
  4. Click Next.
9.3.6.4   Transaction Management Dialog Box
  1. Select the Container-Managed radio button.
  2. In the Transaction Attribute field opposite the onMessage method, verify that Required is selected.
  3. Click Next.
9.3.6.5   Message-Driven Bean Settings Dialog Box
  1. In the Destination Type combo box, select Topic.
  2. In the Destination field, select jms/Topic.
  3. In the Connection Factory field, select jms/TopicConnectionFactory.
  4. Click Next.
9.3.6.6   Environment Entries Dialog Box

Click Next.

9.3.6.7   Enterprise Bean References Dialog Box
  1. Click Add.
  2. In the Coded Name column, enter ejb/MyEjbReference.
  3. In the Type column, select Entity.
  4. In the Interfaces column, select Local.
  5. In the Home Interface column, enter SetupOfficeLocalHome.
  6. In the Local/Remote Interface column, enter SetupOffice.
  7. In the Deployment Settings combo box, select Enterprise Bean Name. In the Enterprise Bean Name field, enter SetupOfficeEJB.
  8. Click Finish. You do not need to enter anything in the other dialog boxes.

9.3.7   Packaging the Office Message-Driven Bean

In this section, you will run the New Enterprise Bean Wizard of the deploytool to package the second message-driven bean. To start the New Enterprise Bean Wizard, follow these steps.

  1. In the tree view, select NewHireApp.
  2. From the File menu, choose New -> Enterprise Bean.
9.3.7.1   Introduction Dialog Box

Click Next.

9.3.7.2   EJB JAR Dialog Box
  1. In the combo box labeled JAR File Location, select Add to Existing JAR File and select Ejb1 (NewHireApp).
  2. Click the Edit button next to the Contents text area.
  3. In the dialog box Edit Contents of Ejb1, choose the directory client_mdb_ent. If the directory is not already in the Starting Directory field, type it in the field, or locate it by browsing through the Available Files tree.
  4. Select the ReserveOfficeMsgBean.class file from the Available Files tree area and click Add.
  5. Click OK.
  6. Click Next.
9.3.7.3   General Dialog Box
  1. In the Bean Type combo box, select the Message-Driven radio button.
  2. Under Enterprise Bean Class, select ReserveOfficeMsgBean. The combo boxes for the local and remote interfaces are grayed out.
  3. In the Enterprise Bean Name field, enter OfficeMDB. This name will represent the message-driven bean in the tree view.
  4. Click Next.
9.3.7.4   Transaction Management Dialog Box
  1. Select the Container-Managed radio button.
  2. In the Transaction Attribute field opposite the onMessage method, verify that Required is selected.
  3. Click Next.
9.3.7.5   Message-Driven Bean Settings Dialog Box
  1. In the Destination Type combo box, select Topic.
  2. In the Destination field, select jms/Topic.
  3. In the Connection Factory field, select jms/TopicConnectionFactory.
  4. Click Next.
9.3.7.6   Environment Entries Dialog Box

Click Next.

9.3.7.7   Enterprise Bean References Dialog Box
  1. Click Add.
  2. In the Coded Name column, enter ejb/MyEjbReference.
  3. In the Type column, select Entity.
  4. In the Interfaces column, select Local.
  5. In the Home Interface column, enter SetupOfficeLocalHome.
  6. In the Local/Remote Interface column, enter SetupOffice.
  7. In the Deployment Settings combo box, select Enterprise Bean Name. In the Enterprise Bean Name field, enter SetupOfficeEJB.
  8. Click Finish. You do not need to enter anything in the other dialog boxes.

9.3.8   Packaging the Schedule Message-Driven Bean

In this section, you will run the New Enterprise Bean Wizard of the deploytool to package the third message-driven bean. To start the New Enterprise Bean Wizard, follow these steps.

  1. In the tree view, select NewHireApp.
  2. From the File menu, choose New -> Enterprise Bean.
9.3.8.1   Introduction Dialog Box

Click Next.

9.3.8.2   EJB JAR Dialog Box
  1. In the combo box labeled JAR File Location, select Add to Existing JAR File and select Ejb1 (NewHireApp).
  2. Click the Edit button next to the Contents text area.
  3. In the dialog box Edit Contents of Ejb1, choose the directory client_mdb_ent. If the directory is not already in the Starting Directory field, type it in the field, or locate it by browsing through the Available Files tree.
  4. Select the ScheduleMsgBean.class file from the Available Files tree area and click Add.
  5. Click OK.
  6. Click Next.
9.3.8.3   General Dialog Box
  1. In the Bean Type combo box, select the Message-Driven radio button.
  2. Under Enterprise Bean Class, select ScheduleMsgBean. The combo boxes for the local and remote interfaces are grayed out.
  3. In the Enterprise Bean Name field, enter ScheduleMDB. This name will represent the message-driven bean in the tree view.
  4. Click Next.
9.3.8.4   Transaction Management Dialog Box
  1. Select the Container-Managed radio button.
  2. In the Transaction Attribute field opposite the onMessage method, verify that Required is selected.
  3. Click Next.
9.3.8.5   Message-Driven Bean Settings Dialog Box
  1. In the Destination Type combo box, select Queue.
  2. In the Destination field, select jms/ScheduleQueue.
  3. In the Connection Factory field, select jms/QueueConnectionFactory.
  4. Click Next.
9.3.8.6   Environment Entries Dialog Box

Click Next.

9.3.8.7   Enterprise Bean References Dialog Box
  1. Click Add.
  2. In the Coded Name column, enter ejb/CompositeEjbReference.
  3. In the Type column, select Entity.
  4. In the Interfaces column, select Local.
  5. In the Home Interface column, enter SetupOfficeLocalHome.
  6. In the Local/Remote Interface column, enter SetupOffice.
  7. In the Deployment Settings combo box, select Enterprise Bean Name. In the Enterprise Bean Name field, enter SetupOfficeEJB.
  8. Click Finish. You do not need to enter anything in the other dialog boxes.

9.3.9   Packaging the Entity Bean

In this section, you will run the New Enterprise Bean Wizard of the deploytool to package the entity bean. To start the New Enterprise Bean Wizard, follow these steps.

  1. In the tree view, select NewHireApp.
  2. From the File menu, choose New -> Enterprise Bean.
9.3.9.1   Introduction Dialog Box

Click Next.

9.3.9.2   EJB JAR Dialog Box
  1. In the combo box labeled JAR File Location, select Add to Existing JAR File and select Ejb1 (NewHireApp).
  2. Click the Edit button next to the Contents text area.
  3. In the dialog box Edit Contents of Ejb1, choose the directory client_mdb_ent. If the directory is not already in the Starting Directory field, type it in the field, or locate it by browsing through the Available Files tree.
  4. Select the following files from the Available Files tree area and click Add: SetupOfficeLocalHome.class, SetupOffice.class, and SetupOfficeBean.class.
  5. Click OK.
  6. Click Next.
9.3.9.3   General Dialog Box
  1. In the Bean Type combo box, select the Entity radio button.
  2. In the Enterprise Bean Class combo box, select SetupOfficeBean.
  3. In the Enterprise Bean Name field, enter SetupOfficeEJB.
  4. In the Local Interfaces combo box, select SetupOfficeLocalHome for Local Home Interface and SetupOffice for Local Interface.
  5. Click Next.
9.3.9.4   Entity Settings Dialog Box
  1. Select the radio button labeled Container managed persistence (2.0).
  2. Select the checkboxes next to all six fields in the Fields To Be Persisted area: employeeId, employeeName, equipmentList, officeNumber, serializedReplyDestination, and replyCorrelationMsgId.
  3. In the Abstract Schema Name field, enter SetupOfficeSchema.
  4. In the Primary Key Class field, enter java.lang.String.
  5. In the Primary Key Field Name field, select employeeId.
  6. Click Next.
9.3.9.5   Transaction Management Dialog Box
  1. Select the Container-Managed radio button.
  2. For all methods, verify that Required is set in the Transaction Attribute column opposite the Local and Local Home radio buttons.
  3. Click Next.
9.3.9.6   Environment Entries Dialog Box

Click Next.

9.3.9.7   Enterprise Bean References Dialog Box

Click Next.

9.3.9.8   Resource References Dialog Box

In this dialog box, you specify the connection factory for the Schedule queue and for the reply. Follow these steps.

  1. Click Add.
  2. In the Coded Name field, enter jms/QueueConnectionFactory.
  3. In the Type field, select javax.jms.QueueConnectionFactory.
  4. In the Authentication field, select Container.
  5. In the Sharable field, make sure that the checkbox is selected.
  6. In the JNDI Name field, enter jms/QueueConnectionFactory.
  7. In the User Name field, enter j2ee.
  8. In the Password field, enter j2ee.
  9. Click Next.
9.3.9.9   Resource Environment References Dialog Box
  1. Click Add.
  2. In the Coded Name field, enter jms/ScheduleQueue--the logical name referenced by SetupOfficeBean.
  3. In the Type field, select javax.jms.Queue.
  4. In the JNDI Name field, enter jms/ScheduleQueue.
  5. Click Next.
9.3.9.10   Security Dialog Box

Use the default Security Identity setting for a session or entity bean, Use Caller ID. Click Next.

9.3.9.11   Review Settings Dialog Box
  1. Check the settings for the deployment descriptor.
  2. Click Finish.

9.3.10   Specifying the Entity Bean Deployment Settings

Generate the SQL for the entity bean and create the table. Follow these steps.

  1. In the tree view, select the SetupOfficeEJB entity bean.
  2. Select the Entity tabbed pane.
  3. Click Deployment Settings.
  4. In the Deployment Settings dialog box, perform these steps.
    1. In the Database Table combo box, select the two checkboxes labeled Create table on deploy and Delete table on undeploy.
    2. Click Database Settings.
    3. In the Deployment Settings dialog box that appears, enter jdbc/Cloudscape in the Database JNDI Name field. Do not enter a user name or a password.
    4. Click OK.
    5. Click Generate Default SQL.
    6. When the SQL Generation Complete dialog appears, click OK.
    7. Click OK in the dialog box.
  5. Choose Save from the File menu to save the application.

9.3.11   Specifying the JNDI Names

Verify that the JNDI names are correct, and add one for the SetupOfficeEJB component. Follow these steps.

  1. In the tree view, select the NewHireApp application.
  2. Select the JNDI Names tabbed pane.
  3. Make sure that the JNDI names appear as shown in Table 9.1 and Table 9.2. You will need to enter SetupOfficeEJB as the JNDI name for the SetupOfficeEJB component.
Table 9.1:    Application Pane
Component Type
Component
JNDI Name
EJB
SetupOfficeEJB
SetupOfficeEJB
EJB
EquipmentMDB
jms/Topic
EJB
OfficeMDB
jms/Topic
EJB
ScheduleMDB
jms/ScheduleQueue

Table 9.2:    References Pane
Ref. Type
Referenced By
Reference Name
JNDI Name
Resource
SetupOfficeEJB
jms/QueueConnectionFactory
jms/QueueConnectionFactory
Env Resource
SetupOfficeEJB
jms/ScheduleQueue
jms/ScheduleQueue
Resource
HumanResourceClient
jms/TopicConnectionFactory
jms/TopicConnectionFactory
Resource
HumanResourceClient
jms/QueueConnectionFactory
jms/QueueConnectionFactory
Env Resource
HumanResourceClient
jms/NewHireTopic
jms/Topic
Resource
EJB1[CMP]
jdbc/Cloudscape

9.4   Deploying and Running the Application

Deploying and running the application involve several steps:

  1. Adding the server, if necessary
  2. Deploying the application
  3. Running the client
  4. Undeploying the application
  5. Removing the application and stopping the server

9.4.1   Adding the Server

Before you can deploy the application, you must make available to the deploytool the J2EE server you started in Section 9.3.1, "Starting the J2EE Server and the Deploytool." Because you started the J2EE server before you started the deploytool, the server, named localhost, probably appears in the tree under Servers. If it does not, do the following.

  1. From the File menu, choose Add Server.
  2. In the Add Server dialog box, enter localhost in the Server Name field.
  3. Click OK. A localhost node appears under Servers in the tree view.

9.4.2   Deploying the Application

To deploy the application, perform the following steps.

  1. From the File menu, choose Save to save the application.
  2. From the Tools menu, choose Deploy.
  3. In the Introduction dialog box, verify that the Object to Deploy selection is NewHireApp and that the Target Server selection is localhost.
  4. Click Next.
  5. In the JNDI Names dialog box, verify that the JNDI names are correct.
  6. Click Next.
  7. Click Finish.
  8. In the Deployment Progress dialog box, click OK when the "Deployment of NewHireApp is complete" message appears.
  9. In the tree view, expand Servers and select localhost. Verify that NewHireApp is deployed.

9.4.3   Running the Client

To run the client, perform the following steps.

  1. At the command line prompt, enter the following:
    runclient -client NewHireApp.ear -name HumanResourceClient -textauth
    
  2. At the login prompts, enter j2ee as the user name and j2ee as the password.
  3. Click OK.

The client program runs in the command window, and output from the application appears in the window in which you started the J2EE server.

9.4.4   Undeploying the Application

To undeploy the J2EE application, follow these steps.

  1. In the tree view, select localhost.
  2. Select NewHireApp in the Deployed Objects area.
  3. Click Undeploy.
  4. Answer Yes in the confirmation dialog.

9.4.5   Removing the Application and Stopping the Server

To remove the application from the deploytool, follow these steps.

  1. Select NewHireApp in the tree view.
  2. Select Close from the File menu.

To delete the queue you created, enter the following at the command line prompt:

j2eeadmin -removeJmsDestination jms/ScheduleQueue

To stop the J2EE server, use the following command:

j2ee -stop

To stop the Cloudscape database server, use the following command:

cloudscape -stop

To exit the deploytool, choose Exit from the File menu.



TOC | Prev | Next | Index

This Tutorial contains information on the 1.3.1 version of the Java 2 Platform, Enterprise Edition.

Copyright © 2002 Sun Microsystems, Inc. All rights reserved.