Somehow, when I tried to write a standalone client I kept coming across the following exception
“ java.lang.ClassCastException: javax.naming.Reference incompatible with javax.jms.ConnectionFactory “.
I followed intructions from here to setup the Queue, after which I created a simple java client to post a message to the Queue:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, “com.ibm.websphere.naming.WsnInitialContextFactory”);
env.put(Context.PROVIDER_URL, “iiop://localhost:2809″);Context jndiContext = null;
try {
jndiContext = new InitialContext(env);
} catch (NamingException e) {System.out.println(“Could not create JNDI API context: ” + e.toString());
System.exit(1);
}ConnectionFactory connectionFactory = (ConnectionFactory) jndiContext.lookup(“jms/JMSExampleConnectionFactory”);
Connection qConn = connectionFactory.createConnection();
Session qSession = qConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue q = (Queue) jndiContext.lookup(“jms/JMSExampleQueue”);MessageProducer producer = qSession.createProducer(q);
TextMessage message = qSession.createTextMessage();
message.setText(“test message”);
producer.send(message);producer.close();
qSession.close();
qConn.close();
Even after switching to the IBM JRE and adding the relevant Jars (as suggested in most places.) the program kept throwing the ClassCast Exception. Just in case you are wondering, the relevant Jars ( found in <Websphere Installation Path>/runtimes/ and <Websphere Installation Path>/lib/WMQ/java/lib/ ) are:
com.ibm.mq.jar
com.ibm.mqjms.jar
com.ibm.ws.webservices.thinclient_6.1.0.jar
dhbcore.jar
ws_runtime.jar
After googling and reading through lot of forum threads I finally stumbled on the solution. To resolve this you also need to add the <Websphere Installation Path>/plugins/com.ibm.ws.runtime_6.1.0.jar to the classpath. Seems simple enough, but it took me ages to find. Hence the post.
Thank you!
Did you switch your JRE on the Server or on the Client?
I tried everything on the client and finally gave up!!! I’m running things as a servlet and it looks to be working fine..
I switched the JRE on the Client. The server is already a IBM AIX box.
Thank you. JMS frustration gone.
I had the same problem in MQ 7.0.1 and solved it by adding the following jars in the CLASSPATH of my Java client:
com.ibm.mq.jar
com.ibm.mqjms.jar
com.ibm.mq.jmqi.jar
dhbcore.jar
fscontext.jar
providerutil.jar
Hope this helps someone someday!
Hi,
I am trying to use JNDI in my standalone java client to connect to the websphere MQ JMS provider.We don’t have any JNDI on JMS provider side.
So I was wondering from where do we get this connectionfactory name.
I am using Queue and Topic names directly and look these up successfully but not sure How I should lookup for connection factory.
Thanks
Anu
Great items from you, man. I’ve understand your stuff prior to and you’re just extremely great. I really like what you have received right here, certainly like what you are stating and the way wherein you assert it. You make it entertaining and you continue to take care of to stay it sensible. I can not wait to read far more from you. This is actually a tremendous web site.
Thanks for this great post, it even helped me 3 years later to get this to work on WAS 7.0. The directory then is:
/SDPShared\plugins\com.ibm.rational.ttt.common.models.core_8.1.50.v20110304_1001\lib\jmslibs
This is for an Websphere BPM 7.5 installation.
Hi,
I would like to say thank you for your posting, which finally helped me to establish connection from Cast Iron to Websphere App Server (7.0) – Message Queue. (in order for Cast Iron to post or pull messages from the Message Queue)
I needed to include the following jars:
com.ibm.mq.jar
com.ibm.mqjms.jar
dhbcore.jar
com.ibm.ws.webservices.thinclient_7.0.0.jar
com.ibm.ws.runtime.jar
com.ibm.ws.sib.client.thin.jms_7.0.0.jar
Katrin
I haven’t really looked into this site for while. Glad it helped.
Awesome post.
Hi , I have a question on including the JMS provider specific jars included in the code. I just want to develop a generic Java agent to talk to a JMS provider
New to JMS and thought I could code with just standard Java SE (for JNDI) and javax,jms (not included in SE library), I could connect to ANY JMS provider.
I have not tried IBM MQ, but I tried on OPEN JMS. The code compiles OK with just the jms1-1.jar (containing javax.jms). I use the following to pass the connection properties
…
Hashtable properties = new Hashtable();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
“org.exolab.jms.jndi.InitialContextFactory”);
properties.put(Context.PROVIDER_URL, “tcp://localhost:3035/”);
…
Looks pretty typical. Until I try to send a message to the OPEN JMS, I got javax.naming.NoInitialContextException: Cannot instantiate class: org.exolab.jms.jndi.InitialContextFactory. It means the JMS provider cannot find the class. The problem get resolved after I add ALL the jar files from the LIB folder. It make no difference in compiling, but now I can access the JMS provider.
After seen Katrin’s response, It seems that a Java client DO need to include vendor specific jars to be able to connect to that provider, even though including those jars are the only thing a Java developer needs to do.
Anyone can confirm on with that?
It seems there is NO way to avoid it. I initial try to stay vendor neutral, but now I have to consider the specific jars.
Unfortunately, I am unable to help. It has been a long while since I wrote any JMS related code.
Thanks in favor of sharing such a fastidious thinking, piece of writing is fastidious, thats why i
have read it fully
I loved as much as you will receive carried out right here.
The sketch is tasteful, your authored material stylish.
nonetheless, you command get got an edginess over that you
wish be delivering the following. unwell unquestionably
come further formerly again as exactly the same nearly very often inside case you shield
this increase.