0

I am using the sample code from https://github.com/AsyncHttpClient/async-http-client and I'm trying to create a GET request:

package asyncHttpClient;

import com.ning.http.client.*;
import java.util.concurrent.Future;

public class AsyncHttpClientExchange {

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

        AsyncHttpClient client = new AsyncHttpClient();
        Future<Response> f = client.prepareGet("http://www.ning.com/").execute();
        Response r = f.get();
        System.out.println(r);
        client.close();

    }

}

When I try to launch it from my eclipse I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at com.ning.http.client.AsyncHttpClient.<clinit>(AsyncHttpClient.java:152)
    at asyncHttpClient.AsyncHttpClientExchange.main(AsyncHttpClientExchange.java:10)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 2 more

Is a problem with my eclipse or with the code? What can I do? Thanks a lot.

user3676015
  • 53
  • 1
  • 11

1 Answers1

2

Your class path is missing slf4j. you can download one from http://www.slf4j.org/download.html

I using Maven build system, add this to dependencies section of pom

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.7</version>
</dependency>
sadhu
  • 1,429
  • 8
  • 14