0

我正在使用来自https://github.com/AsyncHttpClient/async-http-client的示例代码,我正在尝试创建一个 GET 请求:

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

    }

}

当我尝试从我的 Eclipse 启动它时,我收到了这个错误:

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

我的 Eclipse 或代码有问题吗?我能做些什么?非常感谢。

4

1 回答 1

2

您的类路径缺少 slf4j。你可以从下载一个http://www.slf4j.org/download.html

我使用 Maven 构建系统,将其添加dependenciespom

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.7</version>
</dependency>
于 2014-09-25T11:00:39.343 回答