Author |
Message
|
sailussr |
Posted: Mon Mar 02, 2009 12:57 pm Post subject: Jar files to connect to IBM MQ from standalone Java program |
|
|
Newbie
Joined: 02 Mar 2009 Posts: 6
|
All,
I am extremely new to JMS and IBM Websphere.
I am trying to develop a standalone java program to send messages to IBM MQ.
However I am not able to locate where I can find the jar files needed to
access MQ.Can I send messages to MQ using a java program alone without MQ Series Client/Server installation on my local machine.
where can I download the following jar files:
com.ibm.mq.jar ,com.ibm.mqjms.jar
do they come only with server installation?
I searched in different forums for this information, but could see same unresolved problem plenty other places on the net...
Anyone has any suggestions where I can get these jar files? |
|
Back to top |
|
 |
Vitor |
Posted: Mon Mar 02, 2009 2:09 pm Post subject: Re: Jar files to connect to IBM MQ from standalone Java prog |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
sailussr wrote: |
Can I send messages to MQ using a java program alone without MQ Series Client/Server installation on my local machine. |
It's not recommended, and there are good reasons why it's not. Specifically it's better to use the jar files that come with the product than bundle them with your application, so that when the product is updated the jar files are updated.
sailussr wrote: |
where can I download the following jar files:
com.ibm.mq.jar ,com.ibm.mqjms.jar |
They're part of the client installation.
sailussr wrote: |
do they come only with server installation? |
No, they're part of the client installation.
sailussr wrote: |
Anyone has any suggestions where I can get these jar files? |
Download and install the client. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
MQEnthu |
Posted: Mon Mar 02, 2009 9:49 pm Post subject: |
|
|
 Partisan
Joined: 06 Oct 2008 Posts: 329 Location: India
|
|
Back to top |
|
 |
sailussr |
Posted: Mon Mar 09, 2009 7:37 am Post subject: |
|
|
Newbie
Joined: 02 Mar 2009 Posts: 6
|
Thank you for the suggestions.I was able to setup my environment from your suggestions.
I now have trouble in the next step.I am not able to establish connection to Qmgr.Qmgr is up and running.
I get the following error while trying to initialize Context:
javax.naming.NamingException: A class could not be located to initialize the context. Check that you have the com.ibm.mq.pcf.jar in your classpath along with any other jar files that may be needed. [Root exception is java.lang.NoClassDefFoundError: javax/resource/ResourceException]
My piece of code is as follows:
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, mqProperties.getProperty("INITIAL_CONTEXT_FACTORY"));
env.put(Context.PROVIDER_URL, mqProperties.getProperty("ProviderURL"));
Context context = new InitialContext(env);
Initial Context Factory and Provider URL are of the form:
INITIAL_CONTEXT_FACTORY=com.ibm.mq.jms.context.WMQInitialContextFactory
ProviderURL=hostname:port/channel
I have all the required Jar files in my classpath.
The following jars in the classpath:
com.ibm.mq.jar
com.ibm.mq.pcf-6.0.3.jar
com.ibm.mqjms.jar
mqcontext.jar
mqconnector.jar
fscontext.jar
I am not sure what I am missing here.Any suugestions would be greatly helpful.
Thanks |
|
Back to top |
|
 |
zpat |
Posted: Mon Mar 09, 2009 7:44 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
I don't code Java - but is it not telling you the name of the missing jar file?
com.ibm.mq.pcf.jar is not the same as com.ibm.mq.pcf-6.0.3.jar |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Mar 09, 2009 7:58 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
zpat - that could be part of the problem, in that the com.ibm.mq.pcf-6.0.3.jar could have been copied from the MQ Explorer eclipse distribution rather than from the WMQ libraries, or from the MS0B download.
The real problem is that sailussr is trying to use the WMQInitialContext to use the queue manager itself as a JNDI repository, despite this not being best practices and causing a tight coupling between the infrastructure definitions and the application's logical definitions.
sailussr - you don't want to use WMQInitialContextFactory. Use a file context or your app server's real JNDI registry.
And don't take jar files from MQ Explorer directories. |
|
Back to top |
|
 |
sailussr |
Posted: Mon Mar 09, 2009 9:15 am Post subject: |
|
|
Newbie
Joined: 02 Mar 2009 Posts: 6
|
Thank you for the replies.
My java program is a standalone java client to MQ.
Hence I am using WMQInitialContext.
Regarding the jar files, the jars are distributed to us by our MQ Admin.
I think these jar files are from WMQ Libraries.
Please let me know if you think I am still wrong in the way I am trying to initialize the context. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Mar 09, 2009 9:18 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Okay, so it's standalone. So you don't have an app server JNDI to use.
Use the FileContext. Don't use the WMQ Initial Context.
Show your MQ Admin this thread, and let him or her decide if they gave you the right jar files. |
|
Back to top |
|
 |
sailussr |
Posted: Mon Mar 09, 2009 12:53 pm Post subject: |
|
|
Newbie
Joined: 02 Mar 2009 Posts: 6
|
I figured out that connector.jar and jta.jar files are missing in the classpath.
I can now send and read messages from MQ Queue.
All works fine, when I send small Text Messages.
When I send message of considerable length,only a part of the message reaches the queue and the rest of the message is truncated.
This might have been discussed earlier.
I tried searching in the forum, but I was lost and was unable to find the appropriate posts.
Can someone give me links where I can read more about the message length restrictions and how to send/receive such messages
Thank you all for your help!! |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Mar 09, 2009 1:47 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
sailussr wrote: |
I figured out that connector.jar and jta.jar files are missing in the classpath.
I can now send and read messages from MQ Queue.
All works fine, when I send small Text Messages.
When I send message of considerable length,only a part of the message reaches the queue and the rest of the message is truncated.
This might have been discussed earlier.
I tried searching in the forum, but I was lost and was unable to find the appropriate posts.
Can someone give me links where I can read more about the message length restrictions and how to send/receive such messages
Thank you all for your help!! |
Define considerable length. Do you mean over 4MB?  _________________ MQ & Broker admin |
|
Back to top |
|
 |
sailussr |
Posted: Tue Mar 10, 2009 9:22 am Post subject: |
|
|
Newbie
Joined: 02 Mar 2009 Posts: 6
|
I am trying to post this message:
<?xml version="1.0"?>
<ORCHESTRATOR_EVENT>
<COMPLETE>
<EVENT_CODE></EVENT_CODE>
</COMPLETE>
</ORCHESTRATOR_EVENT>
When I read the message from the queue, I see it as follows:
<?xml version="1.0"?>
<ORCHESTRATOR_EVENT>
<COMPLETE>
<EVENT_CODE></EVENT_CODE>
</COMPLETE>
</OR
Another 17 character(s) omitted |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Mar 10, 2009 9:27 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Do not use readUTF() or writeUTF(). |
|
Back to top |
|
 |
sailussr |
Posted: Tue Mar 10, 2009 10:03 am Post subject: |
|
|
Newbie
Joined: 02 Mar 2009 Posts: 6
|
I have started off on a sample code that I got from the internet. The code snippet is as follows:
xmlRequestMessage=
"<?xml version=\"1.0\"?>"+
"\n<ORCHESTRATOR_EVENT>"+
"\n <COMPLETE>"+
"\n <EVENT_CODE></EVENT_CODE>"+
"\n </COMPLETE>"+
"\n</ORCHESTRATOR_EVENT>";
JMSTextMessage message = (JMSTextMessage) session.createTextMessage();
message.setText(xmlRequestMessage);
// Start the connection
connection.start();
sender.send(message);
System.out.println("Sent message:\\n" + message);
JMSMessage receivedMessage = (JMSMessage) receiver.receive(10000);
System.out.println("\\nReceived message:\\n" + receivedMessage);
Not sure if this is the correct approach to start with. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Mar 10, 2009 7:09 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
sailussr wrote: |
JMSMessage receivedMessage = (JMSMessage) receiver.receive(10000);
System.out.println("\\nReceived message:\\n" + receivedMessage);
Not sure if this is the correct approach to start with. |
Change your code just a little bit:
Code: |
Message receivedMessage = receiver.receive(10000);
if ( receivedMessage instanceof TextMessage ) {
TextMessage mytextmsg = (TextMessage) receivedMessage;
String mytext = mytextmsg.getText();
System.out.println(mytext);
} //endif
session.commit();
connection.stop();
receiver.close();
session.close();
connection.close();
|
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
isanchos |
Posted: Mon Sep 28, 2009 8:02 am Post subject: |
|
|
Newbie
Joined: 28 Sep 2009 Posts: 3
|
Hi All!
sailussr wrote: |
I figured out that connector.jar and jta.jar files are missing in the classpath.
I can now send and read messages from MQ Queue.
|
How? Please help me. im add to classpath all jars. No result. I have exception like "A class could not be located to initialize the context. Check that you have the com.ibm.mq.pcf.jar in your classpath along with any other jar files that may be needed." What im doing wrong ?
This is my code
Code: |
Hashtable env = new Hashtable();
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.mq.jms.context.WMQInitialContextFactory");
env.put(javax.naming.Context.PROVIDER_URL,
"localhost:1415/SYSTEM.DEF.SVRCONN");
try {
javax.naming.Context context = new javax.naming.InitialContext(env);
} catch (Exception e) {
|
PS Sorry for my english  |
|
Back to top |
|
 |
|