Java.Lang.ClassCastException in HelloWorldMessageJNDI
Hi
I am getting this error message when I compile and run the Sun provided sample HelloWorldMessageJNDI
Looking up Queue Connection Factory object with lookup name: MyQueueConnectionFactory
Exception in thread "main" java.lang.ClassCastException
at HelloWorldMessageJNDI.<init>(HelloWorldMessageJNDI.java:142)
at HelloWorldMessageJNDI.main(HelloWorldMessageJNDI.java:99)
The code fragment at the specified line number is
qcf = (javax.jms.QueueConnectionFactory) ctx.lookup(MYQCF_LOOKUP_NAME);
Any help would be highly appreciated.
Thanks
Andy
# 1
What is the command you are using when running the sample?Make sure you have jms.jar, imq.jar and fscontext.jar in your CLASSPATH. http://wwws.sun.com/software/products/message_queue/
# 2
i got the same problem when running "HelloWorldMessageJNDI" sample. i do have these three jar in my classpath. could anyone tell me what is the problem, how to fix it...
> What is the command you are using when running the
> sample?
>
> Make sure you have jms.jar, imq.jar and fscontext.jar
> in your CLASSPATH.
# 3
Send us the output when you echo your $CLASSPATH.
What platform are you running on?
What version of java are you using?
What is the exact command you are using?
Send us the exception (if different than previous post).
Thanks.
http://wwws.sun.com/software/products/message_queue/
# 4
Thanks, jnakata,
My environment
OS: Windows XP
jdk: java version "1.4.2_01"
Classpath is set as follows..And I Do Have these 3 jar under c:\lib
C:\Program Files\Sun\MessageQueue3\demo\helloworld\helloworldmessagejndi>echo %c
lasspath%
.;C:\lib\imq.jar;C:\lib\jms.jar;C:\lib\fscontext.jar
Exception Message is the same as previous post..
C:\Program Files\Sun\MessageQueue3\demo\helloworld\helloworldmessagejndi>java He
lloWorldMessageJNDI
Using file:///C:/Temp for Context.PROVIDER_URL
Looking up Queue Connection Factory object with lookup name: MyQueueConnectionFa
ctory
Exception in thread "main" java.lang.ClassCastException
at HelloWorldMessageJNDI.<init>(HelloWorldMessageJNDI.java:150)
at HelloWorldMessageJNDI.main(HelloWorldMessageJNDI.java:103)
thanks again,
# 5
Why are you getting the MQ .jar files under your c:\lib\ ?
You shouldn't be changing/copying the installation of your jar files.
Try setting your CLASSPATH to:
.;C:\Program Files\Sun\MessageQueue3\lib\imq.jar;C:\Program Files\Sun\MessageQueue3\lib\jms.jar;C:\Program Files\Sun\MessageQueue3\lib\fscontext.jar
and running again.
Thanks.
http://wwws.sun.com/software/products/message_queue/
# 6
Hi
I am getting this error message when I compile and run the Sun provided sample HelloWorldMessageJNDI
Looking up Queue Connection Factory object with lookup name: MyQueueConnectionFactory
Exception in thread "main" java.lang.ClassCastException
at HelloWorldMessageJNDI.<init>(HelloWorldMessageJNDI.java:142)
at HelloWorldMessageJNDI.main(HelloWorldMessageJNDI.java:99)
The code fragment at the specified line number is
qcf = (javax.jms.QueueConnectionFactory) ctx.lookup(MYQCF_LOOKUP_NAME);
any body got the solution or have , please help
Thanks
# 7
Can you debug and see what type of objec you are retrieving?-Sagar
# 8
Hi,
The HelloWorldMessageJNDI.java example uses imqobjmgr
to first set up the required queue connection factory and queue
administered objects prior to running the
HelloWorldMessageJNDI application. Running the imqobjmgr
command is made simpler by having 'command files' - files
containing the parameters to imqobjmgr. These are the java
property files .props suffix.
The entire sequence of steps required for setting up and
running the demo is in the README file.
I assume you ran:
imqobjmgr -i add_qcf.props
imqobjmgr -i add_q.props
prior to running the example ?
The command:
imqobjmgr -i list.props
can also be used to verify if the setup worked. The output
should look something like:
% imqobjmgr -i list.props
Listing all administered objects in the object store specified by:
java.naming.factory.initialcom.sun.jndi.fscontext.RefFSContextFactory
java.naming.provider.urlfile:///tmp
Lookup NameObject Class Name
MyQueue com.sun.messaging.Queue
MyQueueConnectionFactorycom.sun.messaging.QueueConnectionFactory
What could go wrong ? If, prior to running this example, you
or someone else had created another administered object of a
different type but at the same lookupname (e.g.
'MyQueueConnectionFactory') the class cast exception would
occur.
However if you run the imqobjmgr commands as above, any
pre-existing objects will be detected and you should see
something like:
Warning: MyQueueConnectionFactory already exists.
Warning: Adding will overwrite the current object.
Are you sure you want to overwrite this object? (y/n)
The output of:
imqobjmgr -i list.props
should show you if/whether the right type of object is at the
lookup location MyQueueConnectionFactory. The value
should be
com.sun.messaging.QueueConnectionFactory which is
compatible with javax.jms.QueueConnectionFactory.
Another possibility is a bad or modified add_qcf.props
file. The line in it that specifies the type of object is:
#
# Object type
#
obj.type=qf
hope this helps,
-isa
http://www.sun.com/software/products/message_queue/index.xml
# 9
Even I faced the problem when I was trying to run the HelloWorldMessageJNDI example. I had configured my Queue Connection Factory as of type javax.jms.ConnectionFactory while the example was trying to cast it to javax.jms.QueueConnectionFactory thereby throwing the ClassCastException.
I changed the Queue Connection Factory to type javax.jms.QueueConnectionFactory in my JMS server and the example worked fine.
Abhi.