Installing couchbase java sdk

hello , i am facing problem installing couchbase java sdk , i dont know proper steps and i hve searched in documentation too , but am not able to understand the way to do

  • my OS is MacOs

please help me out…!

@boby hope this helps

To get started with Java SDK (regardless of OS) you can do a maven install.

in the pom.xml file add the following under dependencies, that is all you need to do when you build / run the project the dependencies should automatically install for you.

<dependencies>
      <dependency>
            <groupId>com.couchbase.client</groupId>
             <artifactId>java-client</artifactId>
            <version>2.7.13</version>
      </dependency>
</dependencies>

The java-client dependency will pull in two more transitive dependencies. One is called com.couchbase.client.core-io and is a internal dependency which performs all the underlying tasks like IO and cluster management. The other dependency is RxJava which is both used internally and exposed as a first-class API to the user in order to perform scalable and performant asynchronous, reactive operations.

Just for your reference here is an example to setup maven java project in macos (you most likely know this but this is just for your reference).

1 Like

@AV25242 hello tq ,
i successfully installed maven but where will i find “pom.xml” file?

You will have to next create a Java- Maven project as explained in the link in my previous post. you should see the file under the application folder.

hii @AV25242

java version “13.0.1” 2019-10-15
Java™ SE Runtime Environment (build 13.0.1+9)
Java HotSpot™ 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)
maven installed
java jdk too

created project

mvn archetype:generate
-DgroupId=TestCases
-DartifactId=RealTimeFramework \
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=false

in pom.xml (i added only dependency ) screenshoot

in App.java( shows error in packages)

package TestCases;
package com.couchbase.client;(tried package com.couchbase.client.java too)

import com.couchbase.client.java.;
import com.couchbase.client.java.kv.
;
import com.couchbase.client.java.json.;
import com.couchbase.client.java.query.
;

public class App
{
public static void main( String args ){
Cluster cluster = Cluster.connect(“localhost”, “Administrator”, “123456”);
Bucket bucket = cluster.bucket(“travel-sample”);
Collection collection = bucket.defaultCollection();
MutationResult upsertResult = collection.upsert(“my-document”, JsonObject.create().put(“name”, “mike”)
);
GetResult getResult = collection.get(“my-document”);
System.out.println(getResult);

QueryResult result = cluster.query("select \"Hello World\" as greeting");
    System.out.println(result.rowsAsObject());

}

}

and just trying to run this app.java

#it shows error in packages
please help me out

@boby please post the exact errors you get.

@daschl hii

@boby if you build a maven project, you need to also run it with the mvn command and not with javac. Again, these are very fundamental java/maven questions and do not have anything to do with the SDK itself. I really recommend you learn how to use java and maven without couchbase and then proceed to add the couchbase library. Otherwise you are adding unneeded complexity to your workflow.

1 Like

@boby I agree with @daschl this has nothing to do with CB SDK, please do a mvn install.

1 Like

tq @daschl @AV25242 i will do as you say