2016-02-13 85 views
1

我試圖連接到Cloudant客戶端,並且我已經在GitHub上找到了一個代碼示例。連接到Cloudant客戶端Java

public ClientBuilder getCloudantClient(String username, String password) { 
    ClientBuilder clientBuilder = ClientBuilder.account(username). 
      username(username).password(password); 
    return clientBuilder; 
} 

理想的情況下,一旦該方法返回,我嘗試做建立並返回數據庫:

CloudantClient client = (CloudantClient) cloudantRestClient.getCloudantClient(USERNAME, PASSWORD).build(); 
Database database = client.database(DATABASE, true); 

但由於某些原因,我得到一個編譯錯誤:

The method account(String) is undefined for the type ClientBuilder

我對Cloudant和JUnit測試的pom.xml依賴關係如下:

<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>3.8.1</version> 
     <scope>test</scope> 
    </dependency> 

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

    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-server</artifactId> 
     <version>1.19</version> 
    </dependency> 

    <dependency> 
     <groupId>org.glassfish.jersey.core</groupId> 
     <artifactId>jersey-client</artifactId> 
     <version>2.22.1</version> 
    </dependency> 

    <dependency> 
     <groupId>org.mockito</groupId> 
     <artifactId>mockito-all</artifactId> 
     <version>1.10.19</version> 
    </dependency> 

我不確定我要去哪裏錯。這是正確的方式去與此?

+2

其中ClientBuilder得到導入到你的代碼?仔細檢查確實是'com.cloudant.client.api.ClientBuilder' – gerrytan

+0

確實解決了它!我導入了javax版本:javax.ws.rs.client.ClientBuilder。謝謝! – Adam

回答

1

你錯了進口ClientBuilder,檢查它的的確com.cloudant.client.api.ClientBuilder