I am following a tutorial about 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 Dependency list:
<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>
But it fails with below exception:
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)
If I add jms.jar and imq.jar from OpenMQ distribution, this example works without any problem. But with maven it doesn't. I think problem should be caused by Maven.