Ask a Question

Getting error while connecting to IBM MQ using Groovy?

Occasional Contributor

Getting error while connecting to IBM MQ using Groovy?

 Using below code:

import javax.jms.*
import java.util.Properties
import javax.naming.Context
import javax.naming.InitialContext

Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
props.setProperty(Context.PROVIDER_URL, "file:/D:/Practice docs/IBM WebSphere MQ/"); 
props.setProperty("DestName", "queue://TestQueueManager/WebSphereQueue")
Context ctx = new InitialContext(props);

QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ctx.lookup("Factory");
Connection connection = connectionFactory.createQueueConnection("Username", "Password"); 
//Connection connection = connectionFactory.createQueueConnection(); // if authenticaiton is disabled
Session queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queueSend = (Queue) ctx.lookup("DestName");
MessageProducer messageProducer = queueSession.createProducer(queueSend);
TextMessage textMessageSend = queueSession.createTextMessage();
            Getting error as :

javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.jndi.fscontext.RefFSContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.jndi.fscontext.RefFSContextFactory]
error at line: 10


And using below snippet of code :

import javax.jms.*;

MQQueueConnectionFactory qcf = new MQQueueConnectionFactory();

// Host and port settings 
qcf.setHostName ("localhost");
qcf.setPort (1414);

// Queue manager and channel — the W-MQ administrator should supply these
qcf.setQueueManager ("TestQueueManager");
qcf.setChannel ("SYSTEM.ADMIN.SVRCONN");

// Although there are many possible values of transport type,
//  only 'client' and 'bindings' work in a Java client. Bindings
//  is a kind of in-memory transport and only works when the client
//  and the queue manager are on the same physical host. In most
//  cases, we need 'client'. 
//qcf.setTransportType (WMQConstants.WMQ_CM_BINDINGS);
qcf .setTransportType (WMQConstants.WMQ_CM_CLIENT);

QueueConnection qc = qcf.createQueueConnection ("Username","password");  //set credentials
// QueueConnection qc = qcf.createQueueConnection (); // if authenticaiton is disabled


Getting error as :

java.lang.NoClassDefFoundError: javax/jms/JMSRuntimeException
error at line: 5


I am not finding \java folder under <IBM MQ Installation> folder. I have copied all jars from /plugins folder. 

Kindly help to resolve.

Showing results for 
Search instead for 
Did you mean: