Author |
Message
|
chanchal |
Posted: Tue Mar 30, 2004 9:14 am Post subject: ResourceException in JMS? |
|
|
Apprentice
Joined: 30 Jan 2004 Posts: 38
|
Hey,I am using a JMS program to send /receive message to/from a Queue.I did set classpath and path for MQ and I created Queue manager QM1 on my machine.when I run the program then it gives javax/Resource/ResourceException.Here is my example program.please tell me whats wrong??
// Import of Sun's JMS interface
import javax.jms.*;
import com.ibm.mq.*;
import com.ibm.mq.jms.*;
public class TestMQ {
public static void main(String args[])
{
invoke();
}
public static void invoke()
{
String QMGR = "QM1";
String QUEUE = "SYSTEM.DEFAULT.LOCAL.QUEUE" ;
String outString ="A simple text message from PTPSample01";
Queue ioQueue= null;
QueueSession session = null;
QueueConnection connection = null;
QueueConnectionFactory factory = null;
try
{
System.out.println("Creating a QueueConnectionFactory");
factory = new MQQueueConnectionFactory();
((MQQueueConnectionFactory)factory).setQueueManager(QMGR);
// Create a QueueConnection from the QueueConnectionFactory
System.out.println("Creating a Connection");
connection = factory.createQueueConnection();
// IMPORTANT: Receive calls will be blocked if the connection is
// not explicitly started, so make sure that we do so!
System.out.println("Starting the Connection");
connection.start();
// We now create a QueueSession from the connection. Here we
// specify that it shouldn't be transacted, and that it should
// automatically acknowledge received messages
System.out.println("Creating a Session");
boolean transacted = false;
session = connection.createQueueSession( transacted,
Session.AUTO_ACKNOWLEDGE);
// Use the session to create the queue object, supplying
// the required MQ-specific parameter
ioQueue = session.createQueue( QUEUE );
// We now use the session to create a QueueSender, passing in the
// destination (the Queue object) as a parameter
System.out.println("Creating a QueueSender");
QueueSender queueSender = session.createSender(ioQueue);
// Create a QueueReceiver in the same way
System.out.println( "Creating a QueueReceiver");
QueueReceiver queueReceiver = session.createReceiver(ioQueue);
// The session is used to create messages, so create an empty
// TextMessage and fill it with some data
System.out.println( "Creating a TextMessage" );
TextMessage outMessage = session.createTextMessage();
System.out.println("Adding Text");
outMessage.setText(outString);
// Ask the QueueSender to send the message we have created
System.out.println( "Sending the message to " + ioQueue.getQueueName() );
queueSender.send(outMessage);
// Now use the QueueReceiver to retrieve the message, blocking
// for a maximum of 1000ms. The receive call returns when the
// message arrives, or after 1000ms, whichever is sooner
System.out.println( "Reading the message back again" );
Message inMessage = queueReceiver.receive(1000);
// Check to see if the receive call has actually returned a
// message. If it hasn't, report this and throw an exception...
if( inMessage == null ) {
System.out.println( "The attempt to read the message back again " +
"failed, apparently because it wasn't there");
throw new JMSException("Failed to get message back again");
}
// ...otherwise display the message
System.out.println( "\n" + "Got message"+": "+inMessage);
// Check that the message received (a) is of the correct type,
// and (b) contains the same text as the one sent, reporting the
// result of these two checks
if( inMessage instanceof TextMessage ) {
// Extract the message content with getText()
String replyString = ((TextMessage) inMessage).getText();
// Test its equality with the message text sent
if( replyString.equals(outString) ) {
System.out.println("Reply string equals original string");
} else {
// If they differ, print them both out
System.out.println("Error! Reply string differs from " +
"original string");
System.out.println("Original string = '" +
outString + "'");
System.out.println("Reply string = '" +
replyString + "'");
}
} else {
// Report that the incoming message was not of the expected
// type, and throw an exception
System.out.println("Reply message was not a TextMessage");
throw new JMSException("Retrieved the wrong type of message");
}
// Remember to call the close() method on all of the objects
// used, to ensure proper clean-up of resources
// Closing QueueReceiver
System.out.println("Closing QueueReceiver");
queueReceiver.close();
// Closing QueueSender
System.out.println("Closing QueueSender");
queueSender.close();
// Closing QueueSesssion.
System.out.println("Closing Session");
session.close();
session = null;
// Closing QueueConnection.
System.out.println("Closing Connection");
connection.close();
connection = null;
} catch( JMSException je ) {
System.out.println("caught JMSException: " + je);
// check for a linked exception that provides more detail
Exception le = je.getLinkedException();
if (le != null) System.out.println("linked exception: "+le);
} catch( Exception e ) {
// This catches any exception thrown in the main body of
// the program, displaying it on screen
System.out.println("Caught exception: " + e );
}
}
} |
|
Back to top |
|
 |
vennela |
Posted: Tue Mar 30, 2004 9:31 am Post subject: |
|
|
 Jedi Knight
Joined: 11 Aug 2002 Posts: 4055 Location: Hyderabad, India
|
Do you have connector.jar in your CLASSPATH. What kind of error are you getting. Post the exact error. |
|
Back to top |
|
 |
chanchal |
Posted: Tue Mar 30, 2004 9:40 am Post subject: |
|
|
Apprentice
Joined: 30 Jan 2004 Posts: 38
|
yes,connector.jar file is there in my classpath and when I debugged my program then I found that line factory.createQueueConnection() raises exception.This is the complete description of error:
Creating a QueueConnectionFactory
Creating a Connection
Exception in thread "main" java.lang.NoClassDefFoundError: javax/resource/Resour
ceException
at com.ibm.mq.MQEnvironment.<clinit>(MQEnvironment.java:242)
at com.ibm.mq.jms.services.ConfigEnvironment.<clinit>(ConfigEnvironment.
java:173)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at com.ibm.mq.jms.MQConnection.<clinit>(MQConnection.java:149)
at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueue
ConnectionFactory.java:142)
at SampleMQ.main(SampleMQ.java:38 |
|
Back to top |
|
 |
vennela |
Posted: Tue Mar 30, 2004 12:34 pm Post subject: |
|
|
 Jedi Knight
Joined: 11 Aug 2002 Posts: 4055 Location: Hyderabad, India
|
NoClassDefFoundError always means you don't have the CLASSPATH set right. How are you saying that you have connector.jar in your CLASSPATH. Post your CLASSPATH. I still doubt if you have your CLASSPATH right. |
|
Back to top |
|
 |
chanchal |
Posted: Wed Mar 31, 2004 7:06 am Post subject: Classpath for MQ |
|
|
Apprentice
Joined: 30 Jan 2004 Posts: 38
|
Actually u r right bcoz MQseries program is not working on my m/c but I did set classpath as follows and dont know where I am wrong.Here is my classpath:
.;C:\Program Files\IBM\WebSphere MQ\Java\lib\com.ibm.mq.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\com.ibm.mqjms.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\jta.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\connector.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\jms.jar;C:\Program Files\j2sdk\netbeans3.5.1\tomcat406\common\lib\servlet.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar |
|
Back to top |
|
 |
chanchal |
Posted: Wed Mar 31, 2004 7:21 am Post subject: |
|
|
Apprentice
Joined: 30 Jan 2004 Posts: 38
|
Here is my PATH variable if it can help in understanding why MQseries program is not executing on my m/c.It gives ResourceException for any MQ program.
C:\Program Files\IBM\WebSphere MQ\bin;C:\Program Files\IBM\WebSphere MQ\Java\lib;C:\Program Files\j2sdk\j2sdk1.4.2\bin;C:\Program Files\Microsoft SQL Server\80\Tools\BINN; |
|
Back to top |
|
 |
chanchal |
Posted: Wed Mar 31, 2004 8:08 am Post subject: |
|
|
Apprentice
Joined: 30 Jan 2004 Posts: 38
|
I am trying to track of errors in my JMS MQ program using org.apache.commons.logging package.When I import this package then it gives error saying this package is not found.Does anybody know how to configure for importing this package?? |
|
Back to top |
|
 |
chanchal |
Posted: Wed Mar 31, 2004 9:12 am Post subject: |
|
|
Apprentice
Joined: 30 Jan 2004 Posts: 38
|
Hey,I tracked the errors and found that it creates connection factory but at the time of creating connection,it gives ResourcesException though I have specified Queue manager and Queue in my m/c.Please check my classpath and path variables and let me know if I do need to set any other things.Earlier these programs were running successfully and now its not working .Please help me.. |
|
Back to top |
|
 |
vennela |
Posted: Wed Mar 31, 2004 10:42 am Post subject: |
|
|
 Jedi Knight
Joined: 11 Aug 2002 Posts: 4055 Location: Hyderabad, India
|
Your CLASSPATH looks OK, but how are you running the program? Using command line.
I compiled your program and set the CLASSPATH as yours and the program worked fine. How are you running the programme
Code: |
C:\samples>set CLASSPATH=.;C:\Program Files\IBM\WebSphere MQ\Java\lib\com.ibm.mq
.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\com.ibm.mqjms.jar;C:\Program Fil
es\IBM\WebSphere MQ\Java\lib\jta.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\
connector.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\jms.jar;C:\Program File
s\j2sdk\netbeans3.5.1\tomcat406\common\lib\servlet.jar;C:\Program Files\Microsof
t SQL Server 2000 Driver for JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL
Server 2000 Driver for JDBC\lib\mssqlserver.jar;C:\Program Files\Microsoft SQL S
erver 2000 Driver for JDBC\lib\msutil.jar
C:\samples>echo %CLASSPATH%
.;C:\Program Files\IBM\WebSphere MQ\Java\lib\com.ibm.mq.jar;C:\Program Files\IBM
\WebSphere MQ\Java\lib\com.ibm.mqjms.jar;C:\Program Files\IBM\WebSphere MQ\Java\
lib\jta.jar;C:\Program Files\IBM\WebSphere MQ\Java\lib\connector.jar;C:\Program
Files\IBM\WebSphere MQ\Java\lib\jms.jar;C:\Program Files\j2sdk\netbeans3.5.1\tom
cat406\common\lib\servlet.jar;C:\Program Files\Microsoft SQL Server 2000 Driver
for JDBC\lib\msbase.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JD
BC\lib\mssqlserver.jar;C:\Program Files\Microsoft SQL Server 2000 Driver for JDB
C\lib\msutil.jar
C:\samples>javac TestMQ.java
C:\samples>java TestMQ
Creating a QueueConnectionFactory
Creating a Connection
Starting the Connection
Creating a Session
Creating a QueueSender
Creating a QueueReceiver
Creating a TextMessage
Adding Text
Sending the message to queue:///SYSTEM.DEFAULT.LOCAL.QUEUE
Reading the message back again
Got message:
JMS Message class: jms_text
JMSType: null
JMSDeliveryMode: 2
JMSExpiration: 0
JMSPriority: 4
JMSMessageID: ID:414d51204d515349514d202020202020efa5694020000901
JMSTimestamp: 1080758456366
JMSCorrelationID:null
JMSDestination: queue:///SYSTEM.DEFAULT.LOCAL.QUEUE
JMSReplyTo: null
JMSRedelivered: false
JMS_IBM_PutDate:20040331
JMSXAppID:C:\WINDOWS\system32\java.exe
JMS_IBM_Format:MQSTR
JMS_IBM_PutApplType:11
JMS_IBM_MsgType:8
JMSXUserID:admin
JMS_IBM_PutTime:18405636
JMSXDeliveryCount:1
A simple text message from PTPSample01
Reply string equals original string
Closing QueueReceiver
Closing QueueSender
Closing Session
Closing Connection
C:\samples> |
Since you say that you have uninstalled and installed, check and see if the jars are actually present. |
|
Back to top |
|
 |
chanchal |
Posted: Wed Mar 31, 2004 10:56 am Post subject: |
|
|
Apprentice
Joined: 30 Jan 2004 Posts: 38
|
I am running in same way.my program is in c:\chanchal and it compiles but when I run as C:\chanchal\java SampleMQ then it shows Exception.Here I am pasting output what I am getting at command line.
C:\chanchal>javac SampleMQ.java
C:\chanchal>java SampleMQ
Creating a QueueConnectionFactory
Creating a Connection
Exception in thread "main" java.lang.NoClassDefFoundError: javax/resource/Resour
ceException
at com.ibm.mq.MQEnvironment.<clinit>(MQEnvironment.java:242)
at com.ibm.mq.jms.services.ConfigEnvironment.<clinit>(ConfigEnvironment.
java:173)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at com.ibm.mq.jms.MQConnection.<clinit>(MQConnection.java:149)
at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueue
ConnectionFactory.java:142)
at SampleMQ.main(SampleMQ.java:3 |
|
Back to top |
|
 |
konda |
Posted: Wed Mar 31, 2004 11:59 am Post subject: |
|
|
Newbie
Joined: 31 Mar 2004 Posts: 5
|
Hi
Try setting the classpath dynamically before running your program. Here is the sample setenv.bat file, make sure JAVA_HOME field pointing to your local JDK bin directory and MQ_JAVA_INSTALL_PATH field pointing to MQ Java installation directory.
Sample: setenv.bat, save this file to your program directory
@echo off
set MQ_JAVA_INSTALL_PATH=c:\Program Files\IBM\WebSphere MQ\java
@rem Java runtime
set JAVA_HOME=C:\jdk1.3\bin
@rem MQ JMS
set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%\lib
set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%\lib\com.ibm.mq.jar
set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%\lib\com.ibm.mqjms.jar
set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%\lib\jms.jar
set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%\lib\jta.jar
set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%\lib\jndi.jar
set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%\lib\ldap.jar
set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%\lib\connector.jar
set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%\lib\fscontext.jar
set MQ=%MQ%;%MQ_JAVA_INSTALL_PATH%\lib\providerutil.jar
set CLASSPATH=%MQ%;%CLASSPATH%
set PATH=%JAVA_HOME%;%MQ_JAVA_INSTALL_PATH%\lib;%PATH%;
Konda |
|
Back to top |
|
 |
chanchal |
Posted: Wed Mar 31, 2004 12:32 pm Post subject: |
|
|
Apprentice
Joined: 30 Jan 2004 Posts: 38
|
I saved the file in C:\chanchal where my MQ program resides and I am running this batch file from there and then running my MQ program but still its giving same error.My all MQ program gives javax/resource/ResourceExc eption and IBM site gives reason of coming this exception as not having connector.jar in classpath but I did set classpath properly and I have tried setting it using environment variables as well as command prompt but its just unable to find my connector.jar.I did no mistake in classpath.I even didn't type it.I am just copying and pasting it and then checked properly. |
|
Back to top |
|
 |
konda |
Posted: Wed Mar 31, 2004 1:13 pm Post subject: |
|
|
Newbie
Joined: 31 Mar 2004 Posts: 5
|
Hi
1) Check connector.jar exist in Java\lib directory
2) If exist rename to xyz.jar and add this file to sentenv.bat file
3) Try again
If not working
1) All the MQ jar files add them to CLASSPATH in both system as well as user variables portion in ENVIRONMENT properties, this may not be right nothing wrong in trying.
2) Try again
Another thing you may consider, check to see if the MQXAi02.dll and mqjbnd05.dll are in the class path.
Good luck
Konda |
|
Back to top |
|
 |
chanchal |
Posted: Wed Mar 31, 2004 1:53 pm Post subject: |
|
|
Apprentice
Joined: 30 Jan 2004 Posts: 38
|
Yes,my jar files are there.I have tried everything and its not working.What should I do now?? |
|
Back to top |
|
 |
vennela |
Posted: Wed Mar 31, 2004 2:01 pm Post subject: |
|
|
 Jedi Knight
Joined: 11 Aug 2002 Posts: 4055 Location: Hyderabad, India
|
Try this:
From a command prompt
Code: |
jar -tvf "c:\Program Files\IBM\WebSphere MQ\java\lib\connector.jar" |
Do you see the class javax/resource/ResourceException |
|
Back to top |
|
 |
|