Solve my error in JMS

Posted on 2012-08-28
Last Modified: 2012-08-28
public class JMSQueue {
    // URL of the JMS server. DEFAULT_BROKER_URL will just mean
    // that JMS server is on localhost
    private static String url = "http://localhost:8161";

    // Name of the queue we will be sending messages to
    private static String subject = "";

    public static void main(String[] args) throws JMSException {
        // Getting JMS connection from the server and starting it
        ConnectionFactory connectionFactory =
            new ActiveMQConnectionFactory(url);
        Connection connection = connectionFactory.createConnection();

        // JMS messages are sent and received using a Session. We will
        // create here a non-transactional session object. If you want
        // to use transactions you should set the first parameter to 'true'
        Session session = connection.createSession(false,

        // Destination represents here our queue 'TESTQUEUE' on the
        // JMS server. You don't have to do anything special on the
        // server to create it, it will be created automatically.
        Destination destination = session.createQueue(subject);

        // MessageProducer is used for sending messages (as opposed
        // to MessageConsumer which is used for receiving them)
        MessageProducer producer = session.createProducer(destination);

        // We will send a small text message saying 'Hello' in Japanese
        TextMessage message = session.createTextMessage("Hello");

        // Here we are sending the message!
        System.out.println("Sent message '" + message.getText() + "'");


it through the error

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpMethod
      at org.apache.activemq.transport.http.HttpTransportFactory.createTransport(
      at org.apache.activemq.transport.TransportFactory.doConnect(
      at org.apache.activemq.transport.TransportFactory.doConnect(
      at org.apache.activemq.transport.TransportFactory.connect(
      at org.apache.activemq.ActiveMQConnectionFactory.createTransport(
      at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(
      at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(
      at org.apache.activemq.ActiveMQConnectionFactory.createConnection(
Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.HttpMethod
      at Method)
      at java.lang.ClassLoader.loadClass(
      at sun.misc.Launcher$AppClassLoader.loadClass(
      at java.lang.ClassLoader.loadClass(
      ... 9 more

http://localhost:8161 it will open the admin page
Question by:stmani2005
    LVL 23

    Expert Comment

    You need httpclient library in the class path of your application.

    You can get it from...
    LVL 35

    Accepted Solution

    Change your URL to ... (assuming that you haven't change any of the defaults)

    private static String url = "tcp://localhost:61616";

    Open in new window


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Java MSI Solution 3 53
    copyEvens challenge 6 48
    wordsWithout 49 64
    array220 challenge 8 32
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
    The viewer will learn how to implement Singleton Design Pattern in Java.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now