Error in loading Send and Recv in RabbtiMQ

163 views
Skip to first unread message

Pankaj Nimgade

unread,
Nov 18, 2014, 9:58:40 AM11/18/14
to rabbitm...@googlegroups.com
am trying to test RabbitMQ on localHost, that I may extrapolate what i would learn to my android project, but it seems quite hard to run the code it self. I have installed Earlang and RabittMQ on my computer and started rabbitMQ server.

the given code by official website of RabbitMQ compiles fine but I can't run as I get this error

`Error: Could not find or load main class Send`   

I have mentioned the code bellow, can anyone help me out with this.

import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.QueueingConsumer;

public class Recv {

 private final static String QUEUE_NAME = "hello";

  public static void main(String[] argv)  throws Exception {

ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();

channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(QUEUE_NAME, true, consumer);

while (true) {
  QueueingConsumer.Delivery delivery = consumer.nextDelivery();
  String message = new String(delivery.getBody());
  System.out.println(" [x] Received '" + message + "'");
}

}
  }    

and the Recv.java is

import com.rabbitmq.client.ConnectionFactory;

import com.rabbitmq.client.Connection;

import com.rabbitmq.client.Channel;


public class Send {


 private final static String QUEUE_NAME = "hello";



    public static void main(String[] argv) throws Exception {

ConnectionFactory factory = new ConnectionFactory();


 factory.setHost("localhost");

  Connection connection = factory.newConnection();

 Channel channel = connection.createChannel();


channel.queueDeclare(QUEUE_NAME, false, false, false, null);
String message = "Hello World!";
channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
System.out.println(" [x] Sent '" + message + "'");

channel.close();
connection.close();

}

Michael Klishin

unread,
Nov 18, 2014, 10:01:35 AM11/18/14
to rabbitm...@googlegroups.com, Pankaj Nimgade
 On 18 November 2014 at 14:58:43, Pankaj Nimgade (pankaj....@gmail.com) wrote:
> I am trying to test RabbitMQ on localHost, that I may extrapolate
> what i would learn to my android project, but it seems quite hard
> to run the code it self. I have installed Earlang and RabittMQ
> on my computer and started rabbitMQ server.
>
> the given code by official website of RabbitMQ compiles fine
> but I can't run as I get this error
>
> `Error: Could not find or load main class Send`

You need to include current directory (which is where tutorials assume .class files are placed)
to JVM classpath, as tutorial 1 demonstrates:

java -cp .:commons-io-1.2.jar:commons-cli-1.1.jar:rabbitmq-client.jar Send

(note that leading dot in the -cp value).

http://www.rabbitmq.com/tutorials/tutorial-one-java.html

There is nothing RabbitMQ or RabbitMQ client-specific about this.
--
MK

Staff Software Engineer, Pivotal/RabbitMQ

Pankaj Nimgade

unread,
Nov 18, 2014, 10:14:50 AM11/18/14
to rabbitm...@googlegroups.com, pankaj....@gmail.com
well, I got all these file mentioned in the same directory called RabbitMQ on my desktop, in that folder I have Send.java, Recv.java and other three jars (rabbitmq-client.jar, commons-io-1.2.jar, commons-cli-1.1.jar) 

Regards
Pankaj Nimgade

Michael Klishin

unread,
Nov 18, 2014, 10:26:34 AM11/18/14
to rabbitm...@googlegroups.com, Pankaj Nimgade
On 18 November 2014 at 15:14:53, Pankaj Nimgade (pankaj....@gmail.com) wrote:
> well, I got all these file mentioned in the same directory called
> RabbitMQ on my desktop, in that folder I have Send.java, Recv.java
> and other three jars (rabbitmq-client.jar, commons-io-1.2.jar,
> commons-cli-1.1.jar)

Pankaj,

Send.class should be on your class path, not Send.java. Sorry, this is a basic Java
question.
Message has been deleted

Pankaj Nimgade

unread,
Nov 21, 2014, 7:26:36 AM11/21/14
to rabbitm...@googlegroups.com, pankaj....@gmail.com
Hi Michael,

well if you check the image I showed you would know that java files have been compiled and .class is there.

Regards
Pankaj Nimgade

Michael Klishin

unread,
Nov 21, 2014, 7:31:43 AM11/21/14
to rabbitm...@googlegroups.com, Pankaj Nimgade
On 21 November 2014 at 12:26:38, Pankaj Nimgade (pankaj....@gmail.com) wrote:
> well if you check the image I showed you would know that java files
> have been compiled and .class is there.

Again, I'm sorry, but this is a basic Java question. T his list is about RabbitMQ.
Reply all
Reply to author
Forward
0 new messages