Solved

Using MQEnvironment class in a java program that is using MQ Series jar files

Posted on 2009-04-07
3
4,773 Views
Last Modified: 2012-05-06
I am new to working with MQ Series programming. I need to hava java program put a message on an mq series queue and then retrieve the answer off of another queue.  To set up parameters for the qManager connection I need to set values in a class named MQEnvironment. The syntax is:

MQEnvironment.channel = "whatever";

When I do this I get a "NoClassDefFoundError /javaa/resource/ResourceExeption" thown by MQEnvironment.java


import com.ibm.mq.*;
 
 
public class testMQ {
	
	// settings for sean kendall's pc local MQ Series tests:
	String requestQManager = "";
	String requestQueueName = "";
 
	String replyQManager = "";
	String replyQueueName = "";
 
 
	
	public static void main(String args[]) {
		new testMQ();
	}
 
	
	public testMQ() {
		try {
			// The Using Java with MQ Series pdf states that channel must be set to
			// the channel name (String) and port to the port number (int) the MQ Series
			// server is listening on
			
			// settings for sean kendall's pc local MQ Series tests:
			//requestQManager = "QM_SKENDALL";
			//requestQueueName = "SYSTEM.DEFAULT.LOCAL.QUEUE";
			//MQEnvironment.hostname = "localhost";
			
 
			// settings for THome's MQ environment:
			String requestQManager = "I2MMA1";
			MQEnvironment.channel = "CLIENT_CMP";
			MQEnvironment.port = 1420;
			MQEnvironment.hostname = "Q4DE8PSAE24.blf.telekom.de";
			requestQueueName = "ESB_CRMT_BLT_REQRESERVATIONSTAT.REQ.IN";
			replyQueueName = "POC_REQRESERVATIONSTAT.REPLY.OUT";
	
	
			//IMPORTANT: all the settings above must be completed befor declaring a new MQQueueManager
	
			//declare qManagers
			MQQueueManager requestQMgr; 
			MQQueueManager replyQMgr; 
			
			
			// Create a connection to the queue managers
			requestQMgr = new MQQueueManager(requestQManager);
			replyQMgr = new MQQueueManager(replyQManager);
			
			// Set up the options on the queue we wish to open...
			// Note. All MQSeries Options are prefixed with MQC in Java.
			int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT ;
			
			// Now specifythe queue that we wish to open,
			// and the open options...
			//MQQueue system_default_local_queue = requestQMgr.accessQueue(requestQueueName, openOptions);
			MQQueue requestQueue = requestQMgr.accessQueue(requestQueueName, openOptions);
			MQQueue replyQueue = replyQMgr.accessQueue(replyQueueName, openOptions);
			
			// Define a simple MQSeries message, and write some text in UTF format..
			//MQMessage hello_world = new MQMessage();
			MQMessage requestMsg = new MQMessage();
			MQMessage replyMsg = new MQMessage();
			
			//hello_world.writeUTF("Hello World!");
			requestMsg.writeUTF("Give Me Something Back");
			
			// specifythe message options...
			MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults, same as MQPMO_DEFAULT
 
			// put the message on the queue
			//system_default_local_queue.put(hello_world,pmo);
			requestQueue.put(requestMsg,pmo);
			
			
			// Set the get message options...
			MQGetMessageOptions gmo = new MQGetMessageOptions(); // accept the defaults
			// same as MQGMO_DEFAULT
			// get the message off the queue...
			//system_default_local_queue.get(retrievedMessage, gmo);
			replyQueue.get(replyMsg, gmo);
			
			
			// And prove we have the message bydisplay ing the UTF message text
			String msgText = replyMsg.readUTF();
			System.out.println("The message is: " + msgText);
			// Close the queue...
			//system_default_local_queue.close();
			requestQueue.close();
			replyQueue.close();
			
			// Disconnect from the queue manager
			requestQMgr.disconnect();
			replyQMgr.disconnect();
			
			
		} catch (Exception e) {
			System.out.println("An exception occurred: " + e.toString());
		}
		
		/*
			// If an error has occurred in the above, tryto identifywhat went wrong
			// Was it an MQSeries error?
			catch (MQException ex) {
				System.out.println("An MQSeries error occurred : Completion code " +
				ex.completionCode + " Reason code " + ex.reasonCode);
			}
			// Was it a Java buffer space error?
			catch (java.io.IOException ex) {
				System.out.println("An error occurred whilst writing to the message buffer: " + ex);
			}
		*/
		} // testMQ constructor
} // end of sample

Open in new window

0
Comment
Question by:skendall66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Gibu George earned 250 total points
ID: 24089334
You need to find the jca.jar and add that to your classpath
0
 
LVL 12

Expert Comment

by:Gibu George
ID: 24089389
I am not sure it is there in jca.jar, the ResourceException is a part of JavaConnector API so I assumed it will be in that.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hashmap order 17 40
running on tomcat not jboss eap 7.0 3 28
java mysql insert application 14 41
Java array 21 80
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question