I am trying to run a very simple ActiveMQ message producer client.  The
source code is provided below.

 

I am launching the app from Eclipse using the Run menu.  I have configured a
Run Configuration For the client app.  On the classpath tab of the Run
Configuration for the app I have included activemq-all-5.5.0.jar,
slf4j-simple-1.5.11 and httpclient-4.1.1.jar.

 

When I run the app I get the following stack trace provided below.  Can
anyone tell me what might be wrong?

 

Thank you.

 

Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/commons/httpclient/HttpMethod

      at
org.apache.activemq.transport.http.HttpTransportFactory.createTransport(Http
TransportFactory.java:75)

      at
org.apache.activemq.transport.TransportFactory.doConnect(TransportFactory.ja
va:141)

      at
org.apache.activemq.transport.TransportFactory.doConnect(TransportFactory.ja
va:51)

      at
org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java
:80)

      at
org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnec
tionFactory.java:243)

      at
org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(Activ
eMQConnectionFactory.java:258)

      at
org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(Activ
eMQConnectionFactory.java:230)

      at
org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConne
ctionFactory.java:178)

      at JMSActiveMQPublisherApp.Execute(JMSActiveMQPublisherApp.java:39)

      at JMSActiveMQPublisherApp.main(JMSActiveMQPublisherApp.java:28)

Caused by: java.lang.ClassNotFoundException:
org.apache.commons.httpclient.HttpMethod

      at java.net.URLClassLoader$1.run(Unknown Source)

      at java.security.AccessController.doPrivileged(Native Method)

      at java.net.URLClassLoader.findClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      ... 10 more

 

import java.util.Vector;

 

import javax.jms.Connection;

import javax.jms.Session;

import javax.jms.Destination;

import javax.jms.DeliveryMode;

import javax.jms.MessageProducer;

import javax.jms.TextMessage;

 

import org.apache.activemq.ActiveMQConnection;

import org.apache.activemq.ActiveMQConnectionFactory;

 

public class JMSActiveMQPublisherApp

{

    private String user         = ActiveMQConnection.DEFAULT_USER;

    private String password     = ActiveMQConnection.DEFAULT_PASSWORD;

    private String url          = "http://localhost:8161/";;

    private String subject      = "Subject.One";

    private int    messageCount = 10;

    private long   sleepTime    = 10000;

 

    

    private Destination destination;

 

    public static void main(String[] args)

      {

      JMSActiveMQPublisherApp app = new JMSActiveMQPublisherApp( );

      app.Execute();

      }

    

    public void Execute( )

    {

        Connection connection = null;

        try

        {

            // Create the connection.

            ActiveMQConnectionFactory connectionFactory =

                  new ActiveMQConnectionFactory(user, password, url);

            connection = connectionFactory.createConnection();

            connection.start();

 

            // Create the session

            // The argument false indicates that this session is not
transacted

            Session session = 

                  connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

 

            // Note that this method is not for creating the physical topic.

            // The physical creation of topics is an administrative task and

            // is not to be initiated by the JMS API.

            //

            // So a publisher can not create new topics.  The topics must

            // be created manually.  The publisher can only send messages to

            // already existing topics.

            //

            // This appears to be a severely limited implementation of the

            // publish/subscribe model!!!

            destination = session.createTopic(subject);

 

            // Create the producer.

            MessageProducer producer = session.createProducer(destination);

            producer.setDeliveryMode(DeliveryMode.PERSISTENT);

 

            // Start sending messages

            SendLoop(session, producer);

 

 

        }

        catch (Exception e)

        {

            System.out.println("Exception: " + e.getMessage());

            e.printStackTrace();

        }

        finally 

        {

            try

            {

                connection.close();

            }

            catch (Throwable ignore)

            {

            }

        }

    }

    

    private void SendLoop(Session session, MessageProducer producer) throws
Exception

    {

 

        for (int i = 0; i < messageCount || messageCount == 0; i++) {

 

            TextMessage message = session.createTextMessage("This is message
" + messageCount + " for topic Subject.One!" );

 

            producer.send(message);

            

            System.out.println("Message " + messageCount + " sent to topic
Subject.One");

 

            Thread.sleep(sleepTime);

        }

    }

}

 

Reply via email to