2016-10-04 48 views
0

我特林與Java程序 以下連接到IBM WebSphere客戶機是代碼:=IBM MQ CLIENT java.lang.UnsatisfiedLinkError中:在的java.library.path異常沒有mqjbnd05

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) 

當我refered這個大家說把mqjbnd.dll在java.library我把這個路徑該文件還仍然沒有工作

+0

建議使用JMS則在100%Java客戶端,如果可能的話。編碼和部署b/c更容易,不需要本地庫。 –

+0

@Matt。錯誤的答案。 (1)即使他們使用JMS,也許他們不想使用JMS&(2),但他們仍然需要特定於供應商的JMS JAR文件。 – Roger

+0

@ Roger7 1)這不是一個答案,它是一個評論。 2)他們在使用非JMS IBM java客戶端庫的本地c庫時遇到問題。使用JMS + IBMMQ-jar是100%的Java,更易於編碼和部署。看過100次... 99次用戶移動到JMS庫。 JMS庫也使用targetClient = 0向另一端的非JMS WMQ客戶端提供後向compat。 –

回答

1

問題中沒有任何內容表明正在使用哪個版本的MQ客戶機,它是如何安裝的,IBM提供的代碼是否工作,或者環境是否設置正確。這使得這更多的是「如何配置和測試MQ客戶端?」這樣的問題,我會這樣回答。

使用IBM的完整客戶端安裝介質始終安裝後臺MQ客戶端。可以使用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

每文檔:

On Windows, all the environment variables are set automatically during installation. On any other platform, you must set them yourself. On a UNIX system, you can use the script setjmsenv (if you are using a 32-bit JVM) or setjmsenv64 (if you are using a 64-bit JVM) to set the environment variables. On AIX, HP-UX, Linux, and Solaris, these scripts are in the MQ_INSTALLATION_PATH/java/bin directory.

IBM提供了大量的示例代碼。在* nix系統上,這是/opt/mqm/samp/。在窗戶上,它在[MQ install directory]\tools。如果安裝了完整的客戶端,請首先嚐試編譯的C代碼,如amqsgetc。這確定了基本連接是否到位。知道通道連接性後,請嘗試使用Java或JMS示例。

回到原來的文章之前,我們可以幫助我們需要知道上面哪些步驟已經完成並且有關配置。否則,你通常會回到一個設置的路徑,在這個設置中,配置幾乎可以保證被清除:「試着在這裏添加這個庫」,或者「嘗試像這樣試試你的CLASSPATH ......」這樣的試驗 - 錯誤方法通常可行,但 不可支持,並隨着時間推移出現問題。

+0

我正在使用WebSphere Explorer 7.5 –

+0

我正在使用mqadv_dev75_windows。 –

+0

我已經完成了你在這個答案中提到的所有步驟,抱怨c代碼也可以工作好 –

3

IBM MQ CLIENT java.lang.UnsatisfiedLinkError: no mqjbnd05 in java.library.path exception

您的標題幾乎說明了一切。 'MQ客戶端'通常意味着隊列管理器是遠程運行到您運行應用程序的位置。但是'no mqjbnd05'意味着您嘗試以綁定模式連接到隊列管理器,隊列管理器與您的隊列管理器在同一臺服務器上運行。

99%的應用程序獲取錯誤的時間是因爲應用程序和隊列管理器在單獨的服務器上運行且應用程序未指定:頻道名稱,主機名/ IP地址&端口號。 (1)客戶端模式 - 表示應用程序和隊列管理器在單獨的服務器上運行,應用程序未指定:通道名稱,主機名/ IP地址& port#。 (2)bindings模式 - 表示應用程序和隊列管理器在相同的服務器上運行(沒有指定網絡信息)。

注意:請勿使用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!"); 
    } 
} 
相關問題