-1

enter image description hereI 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. bellow one is Recv.java

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 Send.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();

}
Pankaj Nimgade
  • 4,529
  • 3
  • 20
  • 30
  • Looks like java problem, not RabbitMQ, isn't it? – pinepain Nov 18 '14 at 15:13
  • 1
    possible duplicate of [What does "Could not find or load main class" mean?](http://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) – pinepain Nov 18 '14 at 15:14
  • thanks I will refer to that to get the answer I am looking for :) . buy the way it is no duplicate, java code is the same I have checked with official website and many tutorials, I believe I missed something in rabbitmq setup – Pankaj Nimgade Nov 18 '14 at 15:17
  • 1
    According to your question text, you have the Send code in the wrong file. – old_sound Nov 18 '14 at 21:14
  • @old_sound sorry I didn't ask this question well, the class files are named as they are shown as class name, anyway I got the code working in android. so it will be alright for now. Thank you. I happy that author of RabbitMQ himself commented. I will get in touch with you if possible. – Pankaj Nimgade Nov 19 '14 at 04:11

1 Answers1

2

On Windows, the classpath delimiters are semicolons, not colons; the tutorial is showing the delimiter used on *nix systems.

So on *nix you'd do:

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

...but on your Windows system use ; rather than ::

java -cp .;commons-io-1.2.jar;commons-cli-1.1.jar;rabbitmq-client.jar Send
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Kendall
  • 36
  • 2