• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help required for JMS on Jboss server  RSS feed

Yogi Mehta
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi All,

I am trying to create a simple JMS Queue program on Jboss Server. But I am getting follwing error. According to this error I am getting SpyQueue object and I am trying to cast it as Queue. Please suggest me what changes i need to do so that I will get Queue object instead of SpyQueue.

java.lang.ClassCastException: org.jboss.mq.SpyQueue
at com.ui.action.HelloG.mains(HelloG.java:27)
at com.ui.action.TestAction.process(TestAction.java:100)
at com.ui.BAction.execute(BAction.java:188)

Here is the Code that I am using. Please help me to get it resolved:

I have created one destination-service.xml file in deploy folder or JBoss app server:

<?xml version="1.0" encoding="UTF-8" ?>
<mbean code="org.jboss.mq.server.jmx.Queue"
<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>

Here is my class HelloG that is having all the logic:

package com.somthing.action;

import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.InitialContext;

public class HelloG
public void mains() throws Exception
// get the initial context
InitialContext ctx = new InitialContext();

// lookup the queue object
Queue queue = (Queue) ctx.lookup("queue/queue0");

// lookup the queue connection factory
QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.

// create a queue connection
QueueConnection queueConn = connFactory.createQueueConnection();

// create a queue session
QueueSession queueSession = queueConn.createQueueSession(false,

// create a queue sender
QueueSender queueSender = queueSession.createSender(queue);

// create a simple message to say "Hello"
TextMessage message = queueSession.createTextMessage("Hello");

// send the message

// print what we did
System.out.println("sent: " + message.getText());

// close the queue connection

This method is called asynchronously by JMS when a message arrives
at the queue. Client applications must not throw any exceptions in
the onMessage method.
@param message A JMS message.
public void onMessage(Message message)
TextMessage msg = (TextMessage) message;
try {
System.out.println("received: " + msg.getText());
} catch (JMSException ex) {


Nilu Deshmukh
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I run the above code -- its give me following exception

what would be the problem ..
I wanted to run Simple JMS code...
but I think i am missing some settings...
I configured -service.xml and -ds.xml files..
Jaikiran Pai
Posts: 10447
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Please create a separate thread to discuss your issue, which is different what the original poster started this thread for. Also, in the new thread provide more details, including the version of JBoss and version of Java. Also provide relevant config files and any relevant code snippets.
Nilu Deshmukh
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Was a Issue of .jar files .
The Issue is resolved.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!