-1

I am using an IBM MQ based jar to browse my queue for specific messages. On building this project through Maven, I come accross this issue package com.ibm.mq does not exist.

I have added this jar in build path and in the lib folder too.

The controller class where I have coded this logic doesn't show any compilation errors due to the com.ibm.mq import. But I face this error while building throught maven !

Should something be done?

Please help.

MQController:

package main.java.controller;

import java.io.*;
import java.util.Properties;
import java.util.Calendar;
import com.ibm.mq.*;

public class MQController {

   private static String    myQmgr  = "QSOA";
   private static String    myQueue = "MQ.EVENTS.POLICY.DUMMY";

   public MQController() {
      myQmgr  = System.getProperty("qm");
      myQueue = System.getProperty("q");
      try {
         Properties props = new Properties(System.getProperties());
         props.load(new BufferedInputStream(new FileInputStream("MQController.properties")));
         System.setProperties(props);
      } catch (Exception e) {
         System.out.println("Error getting MQController.properties: " + e.getMessage());
         System.err.println(e);
      }

      /*if (myQmgr  == null)       {myQmgr  = System.getProperty("qm");}
      if (myQueue == null)       {myQueue = System.getProperty("q");}*/

   }

   public MQController(String[] args) {

      this(); /* call the default constructor */

      for( int i=0; i<args.length; i++ ) {
          String arg = args[i].toLowerCase();

            if( arg.equals("-qm") ) {
                if ( i+1<args.length ) {
                   myQmgr = args[++i];
                } else {
                   System.out.println("didn't specify qmgr, exiting");
                   return;
                }

            } else if( arg.equals("-q") ) {
                if ( i+1<args.length ) {
                   myQueue = args[++i];
                } else {
                   System.out.println("didn't specify queue, exiting");
                   return;
                }

            } else {
              System.out.println( "Unknown argument: " + arg );
            }
      }

   }

   public void myBrowser() {
      MQQueueManager qMgr        = null;
      MQQueue        browseQueue = null;
      int j = 0; /* used as a message counter */

      System.out.println("\n MQController.java - starts here");
      System.out.println("**************************");
      MQException.log = null; /* don't print out any exceptions */
      try {
         qMgr = new MQQueueManager(myQmgr);

         int openOptions = MQC.MQOO_BROWSE;
         browseQueue = qMgr.accessQueue(myQueue, openOptions, null, null, null);
         System.out.println("\n OPEN - '" + myQueue + "'\n\n");
         MQGetMessageOptions gmo = new MQGetMessageOptions(); 
         gmo.options = gmo.options + MQC.MQGMO_BROWSE_NEXT;
         MQMessage myMessage = new MQMessage();
         while (true) {
            myMessage.clearMessage();
            myMessage.correlationId = MQC.MQCI_NONE;
            myMessage.messageId     = MQC.MQMI_NONE;
            browseQueue.get(myMessage, gmo);
            j = j + 1;
            System.out.println(" GET of message number " + j);
            System.out.println("****Message descriptor****\n");
            System.out.println("  StrucId  : 'MD  '"    
                             + "  Version : " + myMessage.getVersion()); 
            System.out.println("  Report   : " + myMessage.report
                             + "  MsgType : " + myMessage.messageType);
            System.out.println("  Expiry   : " + myMessage.expiry
                             + "  Feedback : " + myMessage.feedback);
            System.out.println("  Encoding : " + myMessage.encoding 
                             + "  CodedCharSetId : " + myMessage.characterSet);
            System.out.println("  Format : '" + myMessage.format + "'");
            System.out.println("  Priority : " + myMessage.priority 
                             + "  Persistence : " + myMessage.persistence);
            System.out.print("  MsgId : ");
            System.out.print("  CorrelId : ");
            System.out.println("  BackoutCount : " + myMessage.backoutCount);
            System.out.println("  ReplyToQ     : '" 
                             + myMessage.replyToQueueName + "'");
            System.out.println("  ReplyToQMgr  : '" 
                             + myMessage.replyToQueueManagerName + "'");

            System.out.println("  ** Identity Context");
            System.out.println("  UserIdentifier : '" + myMessage.userId + "'");
            System.out.println("  Accounting Token :");
            System.out.print("   ");
            System.out.println("  ApplIdentityData : '" 
                                + myMessage.applicationIdData + "'");

            System.out.println("  ** Origin Context");
            System.out.println("  PutApplType    : '" 
                               + myMessage.putApplicationType + "'");
            System.out.println("  PutApplName    : '" 
                               + myMessage.putApplicationName + "'");

            System.out.print("  PutDate  : '");
            System.out.print(myMessage.putDateTime.get(Calendar.YEAR));
            int myMonth = myMessage.putDateTime.get(Calendar.MONTH) + 1;
            if (myMonth < 10) {System.out.print("0");}
            System.out.print(myMonth);

            int myDay = myMessage.putDateTime.get(Calendar.DAY_OF_MONTH);
            if (myDay < 10) {System.out.print("0");}
            System.out.print(myDay);
            System.out.print("'    ");

            System.out.print("PutTime  : '");
            int myHour = myMessage.putDateTime.get(Calendar.HOUR_OF_DAY);
            if (myHour < 10) { System.out.print("0"); }
            System.out.print(myHour);

            int myMinute = myMessage.putDateTime.get(Calendar.MINUTE);
            if (myMinute < 10) { System.out.print("0"); }
            System.out.print(myMinute);

            int mySecond = myMessage.putDateTime.get(Calendar.SECOND);
            if (mySecond < 10) { System.out.print("0"); }
            System.out.print(mySecond);

            int myMsec = myMessage.putDateTime.get(Calendar.MILLISECOND);
            myMsec = myMsec/10;
            if (myMsec < 10) { System.out.print("0"); }
            System.out.print(myMsec); 
            System.out.println("'");

            System.out.println("  ApplOriginData : '" 
                               + myMessage.applicationOriginData + "'");
            System.out.println();
            System.out.print("  GroupId : ");
            System.out.println("  MsgSeqNumber   : '" 
                               + myMessage.messageSequenceNumber + "'");
            System.out.println("  Offset         : '" + myMessage.offset + "'");
            System.out.println("  MsgFlags       : '" 
                               + myMessage.messageFlags + "'");
            System.out.println("  OriginalLength : '" 
                               + myMessage.originalLength + "'");
            System.out.println();

            System.out.println("****   Message     ****");
            System.out.println();
            System.out.println(" length - " + myMessage.getMessageLength() 
                             + " bytes\n");
            System.out.println();
            System.out.println();

         }

      } catch (MQException ex) {
         if (ex.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE) {
            System.out.println(" No more messages");
         } else {
            System.out.println("MQ error: Completion code " +
                      ex.completionCode + " Reason code " + ex.reasonCode);
         }
      } catch (java.io.IOException ex) {
         System.out.println("An IO error occurred: " + ex);
      }

      try {
         browseQueue.close();
         System.out.println(" CLOSE of queue");
         qMgr.disconnect();
         System.out.println(" DISCONNECT from queue manager");
      } catch (MQException ex) {
         System.out.println("MQ error: Completion code " +
                      ex.completionCode + " Reason code " + ex.reasonCode);
      }

      System.out.println("**************************");
      System.out.println("MQController.java finished");

   } 

    public static void main( String[] args )     {
       MQController app = new MQController(args);

       if (     (myQmgr==null)  
             || (myQueue==null) ) {
          System.out.println("Usage:");
          System.out.println("java MQController -qm ... -q ...");
          System.out.println("where -qm is the queue manager name");
          System.out.println("      -q  is the queue name");
       } else {
          app.myBrowser();
       }
    }


}

Screenshot: enter image description here

JoshMc
  • 10,239
  • 2
  • 19
  • 38
  • 1
    You use maven to build your Project, so add the library as depenedency to your pom – Jens Sep 28 '17 at 12:48
  • The dependency throws "Missing artifact com.ibm:com.ibm.mq:jar:5.3.07" Mr. Jens ! I have tried that too. –  Sep 28 '17 at 12:51
  • This library is not in the central maven repository. If you do not have your own repository, you have to add it whith scope system – Jens Sep 28 '17 at 12:55
  • 1
    Note that MQ 5.3 has been out of support since September 28 2007. 5.3 CSD 7 was released in 2004, you are running client jar files from 13 years ago that went out of support 10 years ago. I would recommend you go with the MQ v9 Java-Redistributable client, everything you need is includes in com.ibm.mq.allclient.jar. See anser to "[IBM MQ Java Error :: java.lang.ClassNotFoundException: com.ibm.mq.internal.MQCommonServices](https://stackoverflow.com/questions/43843293/ibm-mq-java-error-java-lang-classnotfoundexception-com-ibm-mq-internal-mqcom/43853920#43853920)" for links. – JoshMc Sep 28 '17 at 15:20
  • Another question/answer related to MQ and Maven: [What Is The Convention For Hosting IBM MQ In Maven Repos?](https://stackoverflow.com/questions/45266094/what-is-the-convention-for-hosting-ibm-mq-in-maven-repos/45338151#45338151) – JoshMc Sep 28 '17 at 15:21

1 Answers1

-1

Why do you use Eclipse Java Build Path if you have Maven ?

Instead, you should add this dependency into your pom.xml :

<!-- https://mvnrepository.com/artifact/com.ibm/com.ibm.mq -->
<dependency>
    <groupId>com.ibm</groupId>
    <artifactId>com.ibm.mq</artifactId>
    <version>5.3.07</version>
</dependency>

EDIT

It seems that this dependency refer to a non-existing JAR. I suggest you to refer to the following question :

Mickael
  • 4,458
  • 2
  • 28
  • 40
  • I did try this @Mickael ! Didn't work. It throwed "Missing artifact com.ibm:com.ibm.mq:jar:5.3.07" –  Sep 28 '17 at 12:54
  • This lib is not in the official repository: http://central.maven.org/maven2/com/ibm/com.ibm.mq/5.3.07/com.ibm.mq-5.3.07.jar – Jens Sep 28 '17 at 12:55
  • So suggest me a way then, Mr.Jens. –  Sep 28 '17 at 12:59