Developing a simple JMS application using WSAD


This short tutorial demonstrates how to build a simple Java application that uses MQSeries JMS to put a message to a queue.  The development environment used is the IBM WebSphere Application Developer Studio (V4.02).

First start WSAD and create a new Java project.  We also specify the location of the MQ/JMS JAR files required for building a class.


File -> New -> Project

Select Java and Java Project

Press Next and enter a name for the new project (e.g. My Test JMS Project)

Press Next and select the Libraries tab.  In this property page, select the Add External JARs... button.  A JAR Selection dialog will appear.  Navigate to the folder containing the MQ Java/JMS JAR files from MA88.  By default, this will be:

C:\Program Files\IBM\MQSeries\Java\lib

From there, select the following JAR files:

Hold down the control key while clicking each one to make multiple concurrent selections.

Following this, the property page should look like:

Finally, press Finish to create the new project.


Next create a package that will be used to hold your Java classes (e.g. com.me.mytests).  You can create a package from the

File -> New ->Java Package

menu option.


At this stage, the project and environment is ready for the application and should look similar to the following (click image for a bigger view):

Click to see bigger


Now we are ready to code the Java class that performs the work.

From the File -> New -> Java class, create a new class which is part of the project, has a name and contains a main() method.


In the Java source editor, add the following implementation code:

package com.me.mytests; import javax.jms.*; import com.ibm.mq.jms.*; public class MyTestJMS { public static void main(String[] args) { // Parameters // 1. Queue Name // 2. Queue Manager Name String qName = args[0]; String qManagerName = args[1]; MQQueueConnectionFactory qConnFactory = new MQQueueConnectionFactory(); try { qConnFactory.setQueueManager(qManagerName); QueueConnection qConn = qConnFactory.createQueueConnection(); QueueSession qSession = qConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = new MQQueue("queue:///" + qName); QueueSender qSender = qSession.createSender(queue); TextMessage message = qSession.createTextMessage(); message.setText("Hello World!"); qSender.send(message); qSession.close(); } catch (JMSException e) { System.out.println("Exception: " + e.toString()); } } }

Finally, before running the program, right click the MyTestJMS.java source file in the Packages view and select properties.  Supply both the target queue and queue manager as program arguments:


You are now ready to run the application ...


Last Updated: 03/12/2002