ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » MQ Java Question

Post new topic  Reply to topic
 MQ Java Question « View previous topic :: View next topic » 
Author Message
sevenfan
PostPosted: Thu May 22, 2003 12:15 pm    Post subject: MQ Java Question Reply with quote

Apprentice

Joined: 22 May 2003
Posts: 42

I'm kind of new to MQSeries. I was looking through some of the documentation and ran across some sample code in the Using Java doc directly from IBM. However, I've been unable to make the sample code (application) work.

Can someone provide a simple sample Java class that connects to a queue manager, and places a test message on a queue. In addition, if you could supply command line and any other setup requirements in order for this to work, it would be appreciated.

Thanks.
Back to top
View user's profile Send private message
vennela
PostPosted: Thu May 22, 2003 1:08 pm    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

Here is a sample code.
Name this program as mqget.java

Code:
import com.ibm.mq.*;
   public class mqput extends Object {
   public mqput(){
   }

   public static void main(String args[]){
      String QMGR = args[1];
      String QUEUE = args[0];
      System.out.println("MQPut Program started");
      try{
         MQQueueManager qmgr = new   MQQueueManager(QMGR);
         System.out.println("Connected to QMGR :" + QMGR);
         int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING  ;
         MQQueue InQueue = qmgr.accessQueue(QUEUE , openOptions, null, null, null);MQMD messageDesc = new MQMD();
         MQMessage inMessage = new MQMessage();
         inMessage.writeString("What is your name");
         InQueue.put(inMessage);
         System.out.println("Message Id is :" + inMessage.messageId);
         InQueue.close();
         qmgr.disconnect();
      }
      catch (MQException ex){
           System.out.println("MQ Error - Reason code :" + ex.reasonCode);
      }
      catch(Exception e){
          System.out.println("Error : " + e);
      }
   }
}


Usage:
java mqget QName QMGRName

eg
java mqget SYSTEM.DEFAULT.LOCAL.QUEUE QMGR1

Make sure your classpath is set.

Add the mq jar files to the classpath.
The mq jar files are usually in the <MQInstall directory> \java\lib
If it is a default install directory then it is
C:\Program Files\IBM\WebSphere MQ\Java\lib

If that directory is not present in your computer then you haven't installed the Java Messaging component of MQ.

Hope this helps.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
sevenfan
PostPosted: Thu May 22, 2003 3:32 pm    Post subject: Thanks for the code snippet Reply with quote

Apprentice

Joined: 22 May 2003
Posts: 42

Two questions about running this.
First, I'm guessing that after I compile the class, that to execute, all I should have to do is java -cp [path to jar]/com.ibm.mq.jar mqget.java - correct?

Second, is there anything that I need to do to the MQSeries installation to configure it? Do I need to add this jar to an MQ/lib directory before running?

Thanks for the quick response and in advance to newbie questions.
Back to top
View user's profile Send private message
sevenfan
PostPosted: Thu May 22, 2003 4:03 pm    Post subject: While I'm Here Reply with quote

Apprentice

Joined: 22 May 2003
Posts: 42

I compiled your code, and noticed that the jar files were not in the location you suggested. I put them there, and restarted MQ Series.
I tried running your program and got the following error:Exception in thread "main" java.lang.NoClassDefFoundError: mqput

Since I didn't change the code, I'm wondering what could be the problem.
Thanks again....
Back to top
View user's profile Send private message
vennela
PostPosted: Sat May 24, 2003 10:47 pm    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

"java.lang.NoClassDefFoundError" this is always a classpath problem. Instead of giving your classpath as a command line argument you better set the classpath as an environment variable.

Were you able to compile the code I have posted. If you did then you shouldn't have problems running it. If you had problems compiling find out where the MQ jar files are...
com.ibm.mq.jar

It is more of a Java setting rather than an MQ problem but it's trivial. If you can locate the MQ jar files then you are almost done.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
sevenfan
PostPosted: Tue May 27, 2003 7:09 am    Post subject: At Least it runs now... Reply with quote

Apprentice

Joined: 22 May 2003
Posts: 42

The compile is fine. I found that I needed to modify the classpath to include both the local directory, and also include connector.jar as well as com.ibm.mq.jar (which was all I needed for the compile.
It all worked after that!!!!
Thanks for the help and comments.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » MQ Java Question
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.