IBM MQ Java Error :: java.lang.ClassNotFoundException: com.ibm.mq.internal.MQCommonServices

IBM MQ Java Error :: java.lang.ClassNotFoundException: com.ibm.mq.internal.MQCommonServices

我在尝试使用 MQHeaderIterator 从 MQMessage 对象提取 MQHeaders 时遇到以下错误。我正在使用下面的代码行并获得以下异常。也在类路径中添加了下面的 jar,但仍然显示错误。

使用的库:

com.ibm.mq.jar
com.ibm.mq.headers.jar
com.ibm.mq.commonservices.jar
com.ibm.mq.jmqi.jar
com.ibm.mq.pcf.jar

代码:

//Giving error in this line
MQHeaderIterator it = new MQHeaderIterator(theMessage);

它抛出如下异常。

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.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

请指出此错误的可能原因,主要是在缺少某些 jar 文件时发生 ClassNot Found 错误。我在这里错过了什么吗?

简短回答,将类路径指向原始 IBM MQ 安装位置的 java/lib 目录,其中包含 ALL 个所需的 jar 文件。


更多详情:

IBM 在 v8 之前不支持将 jar 文件复制到不同的位置,在这种情况下,他们已经添加了对重定位的支持,但已将所需的所有内容合并到两个可以重定位的 jar 文件 com.ibm.mq.allclient.jar 和 com.ibm.mq.traceControl.jar从完整的 MQ 服务器或 MQ 客户端安装到您企业中的另一个位置。

有关详细信息,请参阅 IBM 技术说明“Starting with MQ 8.0, you can use Relocatable JAR Files”上的 "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


请注意,所有 MQ 版本 7.1 及更早版本均已从 IBM 终止服务。 IBM MQ v7.5 的服务终止日期为 2018 年 4 月 30 日。

我建议您迁移到尚未宣布服务终止日期的 v8.0 或 v9.0。较新的 MQ 客户端版本可以连接到较旧的 MQ 队列管理器。您可以在以下链接下载 java 仅安装的 MQ 8.0 或 MQ 9.0 jar 文件: