简体   繁体   中英

RabbitMQ - Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

I am trying to use a simple RabbitMQ example and it gives me:

"Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory".

I have amqp-client-4.0.2.jar, slf4j-1.7.25.zip, slf4j-jdk14.jar.zip and log4j-1.2.15.jar on my Build Path.

My code is very basic and I tried a lot of the advices from here on simillar matters, I changed different types of slfj, but it still doesn`t work.

ConnectionFactory factory = new ConnectionFactory();
factory.setHost(HOST);
factory.setUsername(USER);
factory.setPassword(TOKEN);
factory.setVirtualHost(VHOST);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();

String message = "Test!";
channel.basicPublish(EXCHANGE_NAME, QUEUE_NAME, null,              message.getBytes());
System.out.println(" [x] Sent '" + message + "' with id=");

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

Full error:

Exception in thread "main" java.lang.NoClassDefFoundError:     org/slf4j/LoggerFactory
at com.rabbitmq.client.impl.AMQConnection.<clinit>(AMQConnection.java:49)
at com.rabbitmq.client.ConnectionFactory.<init>(ConnectionFactory.java:91)
at ro.test.RMQ_Send_LocalHost.main(RMQ_Send_LocalHost.java:20)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more"

Try adding the slf4j-api dependency to your application:

https://mvnrepository.com/artifact/org.slf4j/slf4j-api

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM