【问题标题】:IBM MQ CLIENT java.lang.UnsatisfiedLinkError: no mqjbnd05 in java.library.path exception [duplicate]IBM MQ 客户端 java.lang.UnsatisfiedLinkError:java.library.path 异常中没有 mqjbnd05 [重复]
【发布时间】:2017-02-12 11:25:35
【问题描述】:

我正在尝试使用 Java 程序连接到 IBM websphere Client 以下是代码:=

import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;


/**
 * Simple example program
 */
public class MQSample {

  // code identifier
  static final String sccsid = "@(#) MQMBID sn=p750-002-131001_DE su=_FswqMCqGEeOZ3ui-rZDONA pn=MQJavaSamples/wmqjava/MQSample.java";

  // define the name of the QueueManager
  private static final String qManager = "QM_ORANGE";
  // and define the name of the Queue
  private static final String qName = "SYSTEM.DEFAULT.LOCAL.QUEUE";
 // private static final String qName = "QM_APPLE";


  public static void main(String args[]) {
    try {

      System.out.println("Connecting to queue manager: " + qManager);
      MQQueueManager qMgr = new MQQueueManager(qManager);
      int openOptions =1| 16;
      System.out.println("Accessing queue: " + qName);
      MQQueue queue = qMgr.accessQueue(qName, openOptions);

      MQMessage msg = new MQMessage();
      msg.writeUTF("Hello, World!");
      MQPutMessageOptions pmo = new MQPutMessageOptions();
      System.out.println("Sending a message...");
      queue.put(msg, pmo);

      // Now get the message back again. First define a WebSphere MQ
      // message
      // to receive the data
    //  MQMessage rcvMessage = new MQMessage();

      // Specify default get message options
    //  MQGetMessageOptions gmo = new MQGetMessageOptions();

      // Get the message off the queue.
     // System.out.println("...and getting the message back again");
     // queue.get(rcvMessage, gmo);

      // And display the message text...
      //String msgText = rcvMessage.readUTF();
     // System.out.println("The message is: " + msgText);

      // Close the queue
      System.out.println("Closing the queue");
      queue.close();

      // Disconnect from the QueueManager
      System.out.println("Disconnecting from the Queue Manager");
      qMgr.disconnect();
      System.out.println("Done!");
    }
    catch (MQException ex) {
      System.out.println("A WebSphere MQ Error occured : Completion Code " + ex.completionCode
          + " Reason Code " + ex.reasonCode);
      ex.printStackTrace();
      for (Throwable t = ex.getCause(); t != null; t = t.getCause()) {
        System.out.println("... Caused by ");
        t.printStackTrace();
      }

    }
    catch (java.io.IOException ex) {
      System.out.println("An IOException occured whilst writing to the message buffer: " + ex);
    }
    return;
  }
}

但现在我收到以下错误

Exception in thread "main" java.lang.UnsatisfiedLinkError: no mqjbnd05 in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at com.ibm.mq.MQSESSION.loadLib(MQSESSION.java:872)
    at com.ibm.mq.server.MQSESSION$1.run(MQSESSION.java:228)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.ibm.mq.server.MQSESSION.<clinit>(MQSESSION.java:222)
    at com.ibm.mq.MQSESSIONServer.getMQSESSION(MQSESSIONServer.java:70)
    at com.ibm.mq.MQSESSION.getSession(MQSESSION.java:492)
    at com.ibm.mq.MQManagedConnectionJ11.<init>(MQManagedConnectionJ11.java:168)
    at com.ibm.mq.MQBindingsManagedConnectionFactoryJ11._createManagedConnection(MQBindingsManagedConnectionFactoryJ11.java:179)
    at com.ibm.mq.MQBindingsManagedConnectionFactoryJ11.createManagedConnection(MQBindingsManagedConnectionFactoryJ11.java:215)
    at com.ibm.mq.StoredManagedConnection.<init>(StoredManagedConnection.java:84)
    at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:168)
    at com.ibm.mq.MQQueueManagerFactory.obtainBaseMQQueueManager(MQQueueManagerFactory.java:772)
    at com.ibm.mq.MQQueueManagerFactory.procure(MQQueueManagerFactory.java:697)
    at com.ibm.mq.MQQueueManagerFactory.constructQueueManager(MQQueueManagerFactory.java:657)
    at com.ibm.mq.MQQueueManagerFactory.createQueueManager(MQQueueManagerFactory.java:153)
    at com.ibm.mq.MQQueueManager.<init>(MQQueueManager.java:451)
    at MQSample.main(MQSample.java:30)

当我提到这个每个人都说把 mqjbnd.dll 放在 java.library 中时,我把那个文件放在那个路径中也仍然无法工作

【问题讨论】:

  • 如果可能,建议使用使用 JMS 的 100% Java 客户端。 b/c 更容易编码和部署,不需要本地库。
  • @马特。不好的答案。 (1) 也许他们不想使用 JMS & (2) 即使他们使用 JMS,他们仍然需要供应商特定的 JMS JAR 文件。
  • @Roger7 1) 这不是答案,而是评论。 2) 他们对使用非 JMS IBM java 客户端库的本机 c 库有问题。使用 JMS+IBMMQ-jar 是 100% java 并且更易于编码和部署。看过 100 次... 99 次用户移动到 JMS 库。 JMS 库还使用 targetClient=0 为另一端的非 JMS WMQ 客户端提供向后兼容。
  • @Matt,他/她的问题不是本机文件与纯 JAR 文件。 99% 的人确定他们有错误的代码并在他们应该以“客户端模式”连接时以“绑定模式”连接。让您大吃一惊:如果您使用“JMS+IBMMQ-jar 是 100% java”并以“绑定模式”连接,那么它将始终使用 mqjbnd05 DLL/共享库!!!!!!
  • @Roger。是的,我知道。除非有极端性能用例(很少出现这种情况),否则出于代码重用和标准一致性的原因,应尽可能避免使用 WMQ 原生 API 和绑定模式方法。

标签: java ibm-mq


【解决方案1】:

问题中没有任何内容表明正在使用哪个版本的 MQ 客户端、它是如何安装的、IBM 提供的代码是否有效,或者环境设置是否正确。这使得这更像是“我如何配置和测试 MQ 客户端?”这样的问题,所以我会这样回答。

后级 MQ 客户端始终使用 IBM 的完整客户端安装媒体进行安装。可以使用 IBM 的纯 Java 安装介质安装较新的客户端。始终建议使用其中一种方法。

要做的一件事(巧合的是,这是最常做的事情)是简单地从 MQ 服务器安装中获取 jar 文件。原因包括:

  • IBM 安装程序放置了一组已知良好的文件。
  • 维护可以应用于使用 IBM 安装程序进行的安装。
  • 使用 IBM 的安装方法时,跟踪目录和 MQClient.ini 文件的位置等内容是可预测的。

因此,首先要确保从 IBM 提供的最新完整客户端或仅 Java 安装介质运行。或者,安装 IBM MQ Advanced for Developers,它将完整的 MQ 安装交付到桌面,包括所有客户端支持。 MQ Advanced for Developers 可供个人免费使用。

在启动代码之前,设置环境。见:
Environment variables relevant to IBM MQ classes for Java
Environment variables used by IBM MQ classes for JMS

根据文档:

在 Windows 上,所有环境变量都是在运行期间自动设置的 安装。在任何其他平台上,您必须自己设置它们。在一个 UNIX 系统,您可以使用脚本 setjmsenv(如果您使用的是 32 位 JVM)或 setjmsenv64(如果您使用 64 位 JVM)来设置 环境变量。在 AIX、HP-UX、Linux 和 Solaris 上,这些 脚本位于 MQ_INSTALLATION_PATH/java/bin 目录中。

IBM 提供了大量示例代码。在 *nix 系统上,这是在 /opt/mqm/samp/。在 Windows 上,它位于 [MQ install directory]\tools 中。如果安装了完整的客户端,请先尝试编译的 C 代码,例如 amqsgetc。这确定了基本连接是否到位。一旦您知道通道连接有效,请尝试 Java 或 JMS 示例。

回到原来的帖子,在我们提供帮助之前,我们需要知道上述哪些步骤已经完成以及有关配置的一些信息。否则,您得到的通常会导致您走上一条几乎可以保证配置被冲洗掉的设置路径:“尝试在此处添加此库”或“尝试像这样处理您的CLASSPATH...”这样的试验-and-error 方法通常有效,但 是不支持的,随着时间的推移会导致问题。

【讨论】:

  • 我正在使用 WebSphere Explorer 7.5
  • 我正在使用 mqadv_dev75_windows。
  • 我已经完成了你在这个答案中提到的所有步骤,抱怨 c 代码也可以正常工作
  • 太棒了!原始帖子向我们展示了代码,但库问题与安装配置以及代码的启动方式有关。如果安装配置内容已排序,您可能希望使用启动器脚本代码更新问题。然后我们可以看到它在哪里运行 setjmsenv 以及在尝试执行类之前的输出。另外,既然这是 MQADV4DEV,那么 QMgr 是本地的吗?
  • 所以你说它不是代码错误它的配置错误。如果是配置错误那么我如何使用连接到服务器中的队列管理器的 websphere explorer 7.5 配置客户端?
【解决方案2】:

IBM MQ 客户端 java.lang.UnsatisfiedLinkError: no mqjbnd05 in java.library.path 异常

您的标题几乎说明了一切。 “MQ 客户端”通常意味着队列管理器远程到您运行应用程序的位置。但是“no mqjbnd05”表示您正在尝试以绑定模式连接到队列管理器,队列管理器与您的队列管理器在同一台服务器上运行。

99% 的应用程序出现错误是因为应用程序和队列管理器在不同的服务器上运行,并且应用程序未指定:通道名称、主机名/IP 地址和端口号。

注意:应用程序可以通过 2 种方式连接到队列管理器: (1) 客户端模式 - 意味着应用程序和队列管理器在不同的服务器上运行,并且应用程序未指定:通道名称、主机名/IP 地址和端口号。

(2) 绑定模式 - 意味着应用程序和队列管理器在相同的服务器上运行(未指定网络信息)。

注意:不要使用 MQEnvironment 类,而是将连接信息放在一个 Hashtable 中并传递给 MQQueueManager 类。 MQEnvironment 不是线程安全的。

这是一个工作示例 MQ 应用程序,它将(客户端模式)连接到远程队列管理器:

import java.io.IOException;
import java.util.Hashtable;

import com.ibm.mq.*;
import com.ibm.mq.constants.CMQC;

/**
 * Java class to connect to MQ. Post and Retrieve messages.
 * 
 * Sample Command Line Parameters 
 *  -h 127.0.0.1 -p 1414 -c TEST.CHL -m MQA1 -q TEST.Q1 -u userid -x password
 */
public class MQClientTest
{
   private Hashtable<String, String> params = null;
   private Hashtable<String, Object> mqht = null;
   private String qManager;
   private String inputQName;

   /**
    * The constructor
    */
   public MQClientTest()
   {
      super();
   }

   /**
    * Make sure the required parameters are present.
    * 
    * @return true/false
    */
   private boolean allParamsPresent()
   {
      boolean b = params.containsKey("-h") && params.containsKey("-p") &&
                  params.containsKey("-c") && params.containsKey("-m") &&
                  params.containsKey("-u") && params.containsKey("-x") &&
                  params.containsKey("-q");
      if (b)
      {
         try
         {
            Integer.parseInt((String) params.get("-p"));
         }
         catch (NumberFormatException e)
         {
            b = false;
         }
      }

      return b;
   }

   /**
    * Extract the command-line parameters and initialize the MQ variables.
    * 
    * @param args
    * @throws IllegalArgumentException
    */
   private void init(String[] args) throws IllegalArgumentException
   {
      params = new Hashtable<String, String>();
      if (args.length > 0 && (args.length % 2) == 0)
      {
         for (int i = 0; i < args.length; i += 2)
         {
            params.put(args[i], args[i + 1]);
         }
      }
      else
      {
         throw new IllegalArgumentException();
      }

      if (allParamsPresent())
      {
         qManager = (String) params.get("-m");
         inputQName = (String) params.get("-q");

         mqht = new Hashtable<String, Object>();

         mqht.put(CMQC.CHANNEL_PROPERTY, params.get("-c"));
         mqht.put(CMQC.HOST_NAME_PROPERTY, params.get("-h"));

         try
         {
            mqht.put(CMQC.PORT_PROPERTY, new Integer(params.get("-p")));
         }
         catch (NumberFormatException e)
         {
            mqht.put(CMQC.PORT_PROPERTY, new Integer(1414));
         }

         mqht.put(CMQC.USER_ID_PROPERTY, params.get("-u"));
         mqht.put(CMQC.PASSWORD_PROPERTY, params.get("-x"));

         // I don't want to see MQ exceptions at the console.
         MQException.log = null;
      }
      else
      {
         throw new IllegalArgumentException();
      }
   }

   /**
    * Method to put then get a message to/from a queue.
    */
   public void putAndGetMessage()
   {
      MQQueueManager qMgr = null;
      MQQueue        queue = null;
      MQMessage      putMessage = null;
      MQMessage      getMessage = null;

      int openOptions = CMQC.MQOO_INPUT_AS_Q_DEF | CMQC.MQOO_OUTPUT + CMQC.MQOO_FAIL_IF_QUIESCING;

      MQGetMessageOptions gmo = new MQGetMessageOptions();
      gmo.options = CMQC.MQGMO_NO_WAIT + CMQC.MQGMO_FAIL_IF_QUIESCING;

      MQPutMessageOptions pmo = new MQPutMessageOptions();
      pmo.options = CMQC.MQPMO_FAIL_IF_QUIESCING;

      String msg = "Hello World, WelCome to MQ.";

      try
      {
         qMgr = new MQQueueManager(qManager, mqht);
         queue = qMgr.accessQueue(inputQName, openOptions);

         putMessage = new MQMessage();
         putMessage.writeUTF(msg);

         // put the message on the queue
         queue.put(putMessage, pmo);

         System.out.println("Message is put on MQ.");

         // get message from MQ.
         getMessage = new MQMessage();
         // assign message id to get message.
         getMessage.messageId = putMessage.messageId;

         /*
          * Tell the queue manager that we want a message with a specific MsgID.
          */
         gmo.matchOptions = CMQC.MQMO_MATCH_MSG_ID;

         // get message options.
         queue.get(getMessage, gmo);

         String retreivedMsg = getMessage.readUTF();
         System.out.println("Message got from MQ: " + retreivedMsg);
      }
      catch (MQException e)
      {
         System.err.println("CC=" + e.completionCode + " : RC=" + e.reasonCode);
      }
      catch (IOException e)
      {
         e.printStackTrace();
      }
      finally
      {
         try
         {
            if (queue != null)
               queue.close();
         }
         catch (MQException e)
         {
            System.err.println("MQCLOSE CC=" + e.completionCode + " : RC="
                  + e.reasonCode);
         }

         try
         {
            if (qMgr != null)
               qMgr.disconnect();
         }
         catch (MQException e2)
         {
            System.err.println("MQDISC CC=" + e2.completionCode + " : RC="
                  + e2.reasonCode);
         }
      }
   }

   public static void main(String[] args)
   {
      System.out.println("Processing Main...");
      MQClientTest clientTest = new MQClientTest();

      try
      {
         // initialize MQ.
         clientTest.init(args);
         // put and retrieve message from MQ.
         clientTest.putAndGetMessage();
      }
      catch (IllegalArgumentException e)
      {
         System.out.println("Usage: java MQClientTest -h host -p port -c channel -m QueueManagerName -q QueueName -u userid -x password");
         System.exit(1);
      }

      System.out.println("Done!");
   }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-22
    • 1970-01-01
    • 2016-12-14
    • 2022-11-08
    • 2020-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多