如何修复Cloudant-client连接错误

时间:2016-03-27 08:10:33

标签: cloudant

我使用cloudant-client-1.0.0.jar进行测试以检查与cloudant服务器的连接:

import com.cloudant.client.api.CloudantClient;
import com.cloudant.client.api.Database;

public class test {

    private CloudantClient client=null;


    public CloudantClient connect(){
        client=new CloudantClient("xxx", "xxx", "xxx");
        System.out.println("Connection successful! "+client.getBaseUri());

        return client;
    }

    public Database getDb(String dbName){

        Database db=connect().database(dbName, true);
        System.out.println("Datase avaible - "+db.getDBUri());

        return db;
    }

    public static void main(String[] args){

        new test().getDb("_user");

    } 
}

但是,系统显示错误:

线程中的异常" main"

java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpEntityEnclosingRequestBase
    at connection.test.connect(test.java:13)
    at connection.test.getDb(test.java:21)
    at connection.test.main(test.java:30)

引起:

java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpEntityEnclosingRequestBase
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more

如何解决?

1 个答案:

答案 0 :(得分:4)

您错过了Apache http客户端库的依赖项。但是,您应该使用Maven,gradle或类似的构建工具来理解Maven存储库。您还应该看一下升级到2.4.1,它包含许多改进和错误修复。