使用Java连接到cloudant

时间:2018-05-08 17:51:23

标签: java cloudant

我目前指的是使用java连接到cloudant的这个github项目。我不知道我哪里出错但是无法连接

我正面临以下错误消息,如我的控制台中所示 java.lang.NoClassDefFoundError: com/cloudant/client/api/ClientBuilder at com.controller.DisplayCheck(controller.java:61) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716) Caused by: java.lang.ClassNotFoundException: com.cloudant.client.api.ClientBuilder at java.net.URLClassLoader.findClass(URLClassLoader.java:434) at com.ws.bootstrap.ExtClassLoader.findClass(ExtClassLoader.java:204) at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:665)

以下是我在POM.xml中声明的依赖项

<dependencies>
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.2</version>
    <scope>compile</scope>
    </dependency>

    <dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>1.6</version>
    <scope>compile</scope>
    </dependency>

    <dependency>
    <groupId>com.cloudant</groupId>
    <artifactId>cloudant-http</artifactId>
    <version>2.12.0</version>
    <scope>compile</scope>
    </dependency>

    <dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>mockwebserver</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
    </dependency>

    <dependency>
    <groupId>org.jmockit</groupId>
    <artifactId>jmockit</artifactId>
    <version>1.34</version>
    <scope>test</scope>
    </dependency>

    <dependency>
    <groupId>org.littleshoot</groupId>
    <artifactId>littleproxy</artifactId>
    <version>1.1.0</version>
    <scope>test</scope>
    </dependency>   

    </dependencies>

下面是我试图从我的控制器测试的代码片段。

CloudantClient client = ClientBuilder.account("account")
                .username("Id")
                .password("pas")
                .build();

        System.out.println("Server Version: " + client.serverVersion());
        List<String> databases = client.getAllDbs();
        System.out.println("All my databases : ");
        for ( String db : databases ) {
            System.out.println(db);
        }

以下是使用的导入

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

1 个答案:

答案 0 :(得分:0)

从您发布的github链接中,您应该拥有这两个依赖项

<dependency>
  <groupId>com.cloudant</groupId>
  <artifactId>cloudant-client</artifactId>
  <version>2.12.0</version>
</dependency>

<dependency>
  <groupId>com.squareup.okhttp3</groupId>
  <artifactId>okhttp-urlconnection</artifactId>
  <version>3.8.1</version>
</dependency>

我在你的依赖关系中看到了某种类似的相似之处,但它们并不完全相同,因此我无法确定它们是什么。