I am getting the below error while trying to extract the MQHeaders using MQHeaderIterator from MQMessage object . I am using the below line of code and getting the below Exception. Added below jar in classpath also but still it showing error.
Libraries used:
com.ibm.mq.jar
com.ibm.mq.headers.jar
com.ibm.mq.commonservices.jar
com.ibm.mq.jmqi.jar
com.ibm.mq.pcf.jar
Code:
//Giving error in this line
MQHeaderIterator it = new MQHeaderIterator(theMessage);
Its throwing Exception as below.
Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/mq/internal/MQCommonServices
at com.ibm.mq.headers.MQHeaderIterator.<init>(MQHeaderIterator.java:112)
at com.test.mq.util.MQClass.main(MQClass.java:69)
Caused by: java.lang.ClassNotFoundException: com.ibm.mq.internal.MQCommonServices
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Please suggest the possible reason for this error mostly ClassNot Found error occurs when some jar file is missing. Am i missing something here?
Short answer, point the classpath to the java/lib directory of the original IBM MQ install location which contains ALL required jar files.
More detail:
IBM does not support copying jar files to different locations until v8 in which case they have added support for relocation but have combined everything needed into two jar files com.ibm.mq.allclient.jar and com.ibm.mq.traceControl.jar which can be relocated from a full MQ Server or MQ Client install to another location in your enterprise.
For more details see the section "Starting with MQ 8.0, you can use Relocatable JAR Files" on IBMs Technote "Starting with MQ 8.0, you can use Relocatable JAR Files".
Note that all MQ versions 7.1 and earlier are end of service from IBM. IBM MQ v7.5 has an end of service date of April 30th 2018.
I would recommend you move to v8.0 or v9.0 which have not had end of service dates announced yet. Newer MQ client versions can connect to older MQ queue managers. You can download a java only install of MQ 8.0 or MQ 9.0 jar files at the links below: