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".
WebSphere MQ 8.0.0 > IBM MQ > Developing applications > Developing
object-oriented applications with IBM MQ > Using IBM MQ classes for
Java > Installation and configuration of IBM MQ classes for Java >
What is installed for IBM MQ classes for Java
Relocatable JAR files
Within an enterprise, the following files can be moved to systems
that need to run IBM MQ classes for Java applications:
- com.ibm.mq.allclient.jar
- com.ibm.mq.traceControl.jar
The file com.ibm.mq.allclient.jar contains the IBM MQ classes for
JMS, the IBM MQ classes for Java, and the PCF and Headers Classes. If
you move this file to a new location, make sure that you take steps to
keep this new location maintained with new IBM MQ Fix Packs. Also,
make sure that the use of this file is made known to IBM Support if
you are getting an interim fix.
To determine the version of the file com.ibm.mq.allclient.jar, use
the command: java -jar com.ibm.mq.allclient.jar
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:
- IBM MQ v8.0 Client
- IBM MQ v9.0 Client