1

我正在关注有关 JMS 的教程。

package org.dedunu.jms.chapter02;

import javax.jms.ConnectionFactory;
import javax.jms.JMSContext;
import javax.jms.Queue;

public class JMS2Receiver {
    public static void main(String[] args) {
        ConnectionFactory connectionFactory = new com.sun.messaging.ConnectionFactory();
        try(JMSContext jmsContext = connectionFactory.createContext();){
            Queue queue = jmsContext.createQueue("TRADE");
            String body = jmsContext.createConsumer(queue).receiveBody(String.class);
            System.out.println(body);
        }

    }
}

Maven依赖列表:

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-core</artifactId>
        <version>5.7.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-ra</artifactId>
        <version>5.10.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-broker</artifactId>
        <version>5.10.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.messaging.mq</groupId>
        <artifactId>imq</artifactId>
        <version>4.6-b01</version>
    </dependency>
</dependencies>

但它失败了,但有以下例外:

Exception in thread "main" java.lang.AbstractMethodError: com.sun.messaging.ConnectionFactory.createContext()Ljavax/jms/JMSContext;
    at org.dedunu.jms.chapter02.JMS2Sender.main(JMS2Sender.java:10)

如果我从 OpenMQ 分发中添加 jms.jar 和 imq.jar,则此示例可以正常工作。但是对于 Maven,它不会。我认为问题应该是由 Maven 引起的。

4

0 回答 0