java - MQ (websphere) 连接问题 java.lang.NoClassDefFoundError

标签 java jms database-connection ibm-mq

我正在尝试从 Java 建立与 MQ 的连接。我正在使用 IBM 的以下示例代码,但它可能已过时。我该如何解决这个问题/我错过了什么?

import com.ibm.mq.*;            // Include the WebSphere MQ classes for Java package
import com.ibm.mq.jmqi.*;
import com.ibm.mq.constants.MQConstants;

public class MQSample
{
    private String qManager = "your_Q_manager";  // define name of queue
    // manager to connect to.
    private MQQueueManager qMgr;                 // define a queue manager
    // object
    public static void main(String args[]) {
        new MQSample();
    }

    public MQSample() {
        try {

            // Create a connection to the queue manager

            qMgr = new MQQueueManager(qManager);

            // Set up the options on the queue we wish to open...
            // Note. All WebSphere MQ Options are prefixed with MQC in Java.

            int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF |
                    MQConstants.MQOO_OUTPUT ;

            // Now specify the queue that we wish to open,
            // and the open options...

            MQQueue system_default_local_queue =
                    qMgr.accessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE",
                            openOptions);

            // Define a simple WebSphere MQ message, and write some text in UTF format..

            MQMessage hello_world = new MQMessage();
            hello_world.writeUTF("Hello World!");

            // specify the message options...

            MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the // defaults,
            // same as MQPMO_DEFAULT

            // put the message on the queue

            system_default_local_queue.put(hello_world,pmo);

            // get the message back again...
            // First define a WebSphere MQ message buffer to receive the message into..

            MQMessage retrievedMessage = new MQMessage();
            retrievedMessage.messageId = hello_world.messageId;

            // Set the get message options...

            MQGetMessageOptions gmo = new MQGetMessageOptions(); // accept the defaults
            // same as  MQGMO_DEFAULT
            // get the message off the queue...

            system_default_local_queue.get(retrievedMessage, gmo);

            // And prove we have the message by displaying the UTF message text

            String msgText = retrievedMessage.readUTF();
            System.out.println("The message is: " + msgText);
            // Close the queue...
            system_default_local_queue.close();
            // Disconnect from the queue manager

            qMgr.disconnect();
        }
        // If an error has occurred in the above, try to identify what went wrong
        // Was it a WebSphere MQ error?
        catch (MQException ex)
        {
            System.out.println("A WebSphere MQ error occurred : Completion code " +
                    ex.completionCode + " Reason code " + ex.reasonCode);
        }
        // Was it a Java buffer space error?
        catch (java.io.IOException ex)
        {
            System.out.println("An error occurred whilst writing to the message buffer: " + ex);
        }
    }
} // end of sample

我得到的错误:

"C:\Program Files\Java\jdk1.7.0_09\bin\java" -Didea.launcher.port=7536 "-Didea.launcher.bin.path=M:\IntelliJ IDEA 12.1.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.7.0_09\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\access-bridge.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext\zipfs.jar;M:\untitled\out\production\untitled;D:\MavenRepository\com\ibm\mq\mq\7.0.1.1\mq-7.0.1.1.jar;D:\MavenRepository\com\ibm\mq\jmqi\7.0.1.1\jmqi-7.0.1.1.jar;M:\Monitor_NEW\Engine\lib\ojdbc14_g-10.2.0.jar;D:\MavenRepository\com\ibm\mq\mqjms\7.0.1.1\mqjms-7.0.1.1.jar;M:\IntelliJ IDEA 12.1.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain MQSample
Exception in thread "main" java.lang.NoClassDefFoundError: javax/resource/ResourceException
    at com.ibm.mq.MQQueueManager.<clinit>(MQQueueManager.java:153)
    at MQSample.<init>(MQSample.java:28)
    at MQSample.main(MQSample.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.ClassNotFoundException: javax.resource.ResourceException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 8 more

最佳答案

将 connector-1.0.jar 依赖项添加到您的项目中。

关于java - MQ (websphere) 连接问题 java.lang.NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17566479/

相关文章:

jms - 骡子 ESB : Setup JMS Endpoint for WMQ Queue

database - 如何使用 gorm 设置特定的数据库模式?

WPF - 绑定(bind)到 Oracle 数据库

java - Json 版本的 XMLElements 选择

java - ActiveMQ 消费者级别超时

java - 使用 JMS 满足此需求的最佳方法是什么

java - 如何从 Tomcat 的 JNDI 获取 PoolingDataSource

java - 在 JBoss 5.1.0.GA 上部署时出现 "Persistence provider caller does not implement the EJB3 spec correctly."警告

java - 如果我重写 onTouchEvent 方法, map View 缩放控件不会显示

java - 为什么此照明代码仅适用于单个灯光,而当我添加多个灯光时会中断?