Running the simplemessage Example
You can use either NetBeans IDE or Ant to build, package, deploy, and run the simplemessage example.
Administered Objects for the simplemessage Example
This example requires the following:
A JMS connection factory resource
A JMS destination resource
If you have run the simple JMS examples in Chapter 47, Java Message Service Concepts and have not deleted the resources, you already have these resources. Otherwise, the resources will be created automatically when you deploy the application.
For more information on creating JMS resources, see JMS Administered Objects for the Synchronous Receive Example.
To Run the simplemessage Application Using NetBeans IDE
- From the File menu, choose Open Project.
- In the Open Project dialog, navigate to:
tut-install/examples/ejb/
- Select the simplemessage folder.
- Select the Open as Main Project check box and the Open Required Projects check box.
- Click Open Project.
- In the Projects tab, right-click the simplemessage project and choose Build.
This task packages the application client and the message-driven bean, then creates a file named simplemessage.ear in the dist directory.
- Right-click the project and choose Run.
This command creates any needed resources, deploys the project, returns a JAR file named simplemessageClient.jar, and then executes it.
The output of the application client in the Output pane looks like this (preceded by application client container output):
Sending message: This is message 1 Sending message: This is message 2 Sending message: This is message 3 To see if the bean received the messages, check <install_dir>/domains/domain1/logs/server.log.
The output from the message-driven bean appears in the server log (domain-dir/logs/server.log), wrapped in logging information.
MESSAGE BEAN: Message received: This is message 1 MESSAGE BEAN: Message received: This is message 2 MESSAGE BEAN: Message received: This is message 3
The received messages may appear in a different order from the order in which they were sent.
To Run the simplemessage Application Using Ant
- In a terminal window, go to:
tut-install/examples/ejb/simplemessage/
- To compile the source files and package the application, use the following command:
ant
This target packages the application client and the message-driven bean, then creates a file named simplemessage.ear in the dist directory.
By using resource injection and annotations, you avoid having to create deployment descriptor files for the message-driven bean and application client. You need to use deployment descriptors only if you want to override the values specified in the annotated source files.
- To create any needed resources, deploy the application, and run the client using
Ant, use the following command:
ant run
Ignore the message that states that the application is deployed at a URL.
The output in the terminal window looks like this (preceded by application client container output):
Sending message: This is message 1 Sending message: This is message 2 Sending message: This is message 3 To see if the bean received the messages, check <install_dir>/domains/domain1/logs/server.log.
In the server log file, the following lines appear, wrapped in logging information:
MESSAGE BEAN: Message received: This is message 1 MESSAGE BEAN: Message received: This is message 2 MESSAGE BEAN: Message received: This is message 3
The received messages may appear in a different order from the order in which they were sent.
Removing the Administered Objects for the simplemessage Example
After you run the example, you can use NetBeans IDE to remove the connection factory and queue, as described in To Delete JMS Resources Using NetBeans IDE. If you are not using NetBeans IDE, you can use the asadmin list-jms-resources command to list the resources, and the asadmin delete-jms-resource command to remove each one.