A newer version of this documentation is available.

View Latest

Installing the Couchbase Java SDK

      +
      In this tutorial, you’re going to create a skeleton application for interacting with the student database you created previously.

      Prerequisites

      Java is a fairly popular programming language these days, so we’re going to use it to build our student/course application. To keep things as light as possible (this is a tutorial, after all), we’re not going to worry about building a web front end or REST service, just a few methods to read/write our documents to the database.

      You will need a few things installed on your machine before you begin:

      • The Java Software Development Kit (version 8+)

      • Apache Maven (version 3+)

      SDKMan is the easiest way to install and manage JDKs and Maven on your host machine.

      Set up

      Create the following directory structure on your machine:

      📂 ~ (your home directory)
        📂 student
          📂 src
            📂 main
              📂 java

      Create a new file in the directory called pom.xml in the student directory. The pom file should be populated as follows:

      pom.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <project xmlns="http://maven.apache.org/POM/4.0.0"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
          <modelVersion>4.0.0</modelVersion>
      
          <groupId>org.example</groupId>
          <artifactId>couchbase-java</artifactId>
          <version>1.0-SNAPSHOT</version>
      
          <properties>
              <maven.compiler.source>16</maven.compiler.source>
              <maven.compiler.target>16</maven.compiler.target>
              <encoding>UTF-8</encoding>
              <project.build.sourceEncoding>${encoding}</project.build.sourceEncoding>
              <project.reporting.outputEncoding>${encoding}</project.reporting.outputEncoding>
              <project.resources.sourceEncoding>${encoding}</project.resources.sourceEncoding>
              <archetype.encoding>${encoding}</archetype.encoding>
          </properties>
      
          <dependencies>    (1)
              <dependency>
                  <groupId>com.couchbase.client</groupId>
                  <artifactId>java-client</artifactId>
                  <version>3.2.6</version>
              </dependency>
          </dependencies>
      
      </project>
      1 The dependencies section lists all the libraries required to build the application. In our case, we only need the Couchbase client SDK (version 3.2.1, in this case).
      📂 ~ (your home directory)
        📂 student
          📃 pom.xml ⬅ here!
        📂 src
          📂 main
            📂 java

      You can test the setup is correct by opening a terminal window and changing to the student directory. Run the build script to pull in all the dependencies.

      mvn install

      Next steps

      You’re now ready to write your first Couchbase application.