最近工作上需要利用Java開發連接MQ 做交易,測試期間以應用程式模式連接 MQ, 一切設定都寫在 MQ.properties 當一切電文都測試無誤改以 Web Application (JSP) 呼叫電文 method 時卻會出現 NoClassDefFoundError 如下 :
java.lang.NoClassDefFoundError
at com.ibm.mq.MQSESSIONServer.getMQSESSION(MQSESSIONServer.java:67)
at com.ibm.mq.MQSESSION.getSession(MQSESSION.java:240)
at com.ibm.mq.MQManagedConnectionJ11.
at com.ibm.mq.MQBindingsManagedConnectionFactoryJ11._createManagedConnection(MQBindingsManagedConnectionFactoryJ11.java:136)
at com.ibm.mq.MQBindingsManagedConnectionFactoryJ11.createManagedConnection(MQBindingsManagedConnectionFactoryJ11.java:154)
at com.ibm.mq.StoredManagedConnection.
at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:150)
at com.ibm.mq.MQQueueManager.obtainBaseMQQueueManager(MQQueueManager.java:560)
at com.ibm.mq.MQQueueManager.construct(MQQueueManager.java:509)
at com.ibm.mq.MQQueueManager.
at com.feib.cbd.unisys.gateway.AgentMQRFH2.nightQuery(AgentMQRFH2.java:254)
at _iccardlost__jsp._jspService(D:\Resin\doc\ics\IcCardLost.jsp:51)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.subservice(Page.java:485)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
at com.caucho.server.http.Invocation.service(Invocation.java:312)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:221)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
at java.lang.Thread.run(Thread.java:536)
一開始也以為是因為 classpath 沒設, 應有的 MQ jar files classpath 沒指定.上 Google 找解答基本上也是如此或是說 .dll (Windows) 或 .so (Linux , UNIX) 沒有放對.
MQ jar files 放到 Resin AP Server 各種 lib目錄, 有時還會出現 UnsatisfiedLinkError 如下 :
java.lang.UnsatisfiedLinkError: no mqjbnd02 in java.library.pathat java.lang.ClassLoader.loadLibrary(ClassLoader.java:1403)at java.lang.Runtime.loadLibrary0(Runtime.java:788)at java.lang.System.loadLibrary(System.java:832)at com.ibm.mq.server.MQSESSION.(MQSESSION.java:139)at com.ibm.mq.MQSESSIONServer.getMQSESSION(MQSESSIONServer.java:67)at com.ibm.mq.MQSESSION.getSession(MQSESSION.java:240)at com.ibm.mq.MQManagedConnectionJ11.(MQManagedConnectionJ11.java:148)at com.ibm.mq.MQBindingsManagedConnectionFactoryJ11._createManagedConnection(MQBindingsManagedConnectionFactoryJ11.java:136)at com.ibm.mq.MQBindingsManagedConnectionFactoryJ11.createManagedConnection(MQBindingsManagedConnectionFactoryJ11.java:154)at com.ibm.mq.StoredManagedConnection.(StoredManagedConnection.java:80)at com.ibm.mq.MQSimpleConnectionManager.allocateConnection(MQSimpleConnectionManager.java:150)at com.ibm.mq.MQQueueManager.obtainBaseMQQueueManager(MQQueueManager.java:560)at com.ibm.mq.MQQueueManager.construct(MQQueueManager.java:509)at com.ibm.mq.MQQueueManager.(MQQueueManager.java:286)at com.feib.cbd.unisys.gateway.AgentMQRFH2.nightQuery(AgentMQRFH2.java:219)at _queryaccountstatus__jsp._jspService(D:\Resin\doc\ics\queryAccountStatus.jsp:56)at com.caucho.jsp.JavaPage.service(JavaPage.java:75)at com.caucho.jsp.Page.subservice(Page.java:485)at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)at com.caucho.server.http.Invocation.service(Invocation.java:312)at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:221)at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)at com.caucho.server.TcpConnection.run(TcpConnection.java:137)at java.lang.Thread.run(Thread.java:536)
最後真正的原因是 MQ.properties 檔讀不到,改用 hard code 方式指定 MQ Server ip, port 之後一切就正常,供大家參考 !