10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

} else {<br />

System.out.println("Message is not a " + "TextMessage");<br />

}<br />

} catch (JMSException e) {<br />

System.out.println("JMSException in onMessage(): " + e.toString());<br />

} catch (Throwable t) {<br />

System.out.println("Exception in onMessage():" + t.getMessage());<br />

}<br />

You will use the connection factory and destinations you created in “Creating JMS<br />

Administered Objects for the Synchronous Receive Example” on page 910.<br />

Compiling and Packaging the AsynchConsumer Client<br />

To compile and package the AsynchConsumer example using NetBeans IDE, follow these steps:<br />

1. In NetBeans IDE, choose Open Project from the File menu.<br />

2. In the Open Project dialog, navigate to<br />

tut-install/javaeetutorial5/examples/jms/simple/.<br />

3. Select the asynchconsumer folder.<br />

4. Select the Open as Main Project check box.<br />

5. Click Open Project.<br />

6. Right-click the project and choose Build.<br />

To compile and package the AsynchConsumer example using Ant, follow these steps:<br />

1. In a terminal window, go to the asynchconsumer directory:<br />

cd ../../asynchconsumer<br />

2. Type the following command:<br />

ant<br />

<strong>The</strong> targets package both the main class and the message listener class in the JAR file and place<br />

the file in the dist directory for the example.<br />

Running the Clients for the Asynchronous Receive Example<br />

To run the programs using NetBeans IDE, follow these steps.<br />

1. Run the AsynchConsumer example:<br />

a. Right-click the asynchconsumer project and choose Properties.<br />

b. Select Run from the Categories tree.<br />

c. In the Arguments field, type the following:<br />

topic<br />

Writing Simple JMS Client Applications<br />

Chapter 31 • <strong>The</strong> <strong>Java</strong> Message Service API 917

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!