CINXE.COM

Couchbase Lite on Java — Installing | Couchbase Docs

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv=content-security-policy content="default-src 'none'; script-src 'self' 'unsafe-eval' 'unsafe-inline' https:; style-src 'self' 'unsafe-inline' https:; font-src 'self' https://fonts.gstatic.com; frame-src 'self' https:; img-src 'self' data: https:; connect-src 'self' https:; worker-src blob:;"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://metrics.couchbase.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-MVPNN2');</script> <!-- End Google Tag Manager --> <title>Couchbase Lite on Java&#8201;&#8212;&#8201;Installing | Couchbase Docs</title> <link rel="canonical" href="https://docs.couchbase.com/couchbase-lite/current/java/gs-install.html"> <link rel="stylesheet" href="../../../_/css/site.css"> <script src="../../../_/js/vendor/jquery.js"></script> <script src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js" data-domain-script="748511ff-10bf-44bf-88b8-36382e5b5fd9"></script> <script>function OptanonWrapper(){}</script> <meta name="description" content="Couchbase Lite on Java -- a framework for developing offline-first Java applications for mobile and edge"> <meta name="keywords" content="mobile edge nosql api Java JVM web-app device-app"> <link rel="schema.dcterms" href="https://purl.org/dc/terms/"> <meta name="dcterms.subject" content="couchbase-lite"> <meta name="dcterms.identifier" content="3.2"> <meta name="page-url" content="/couchbase-lite/current/java/gs-install.html"> <meta name="page-nav-header-levels" content="0"> <meta name="docsearch:component" content="couchbase-lite"> <meta name="docsearch:component_title" content="Couchbase Lite"> <meta name="docsearch:cversion" content="3.2"> <meta name="docsearch:component_version" content="couchbase-lite@3.2"> <meta name="docsearch:module" content="java"> <meta name="docsearch:breadcrumbs" content="Couchbase Lite / Java / Start Here! / Install"> <meta name="docsearch:topic_type" content=""> <meta name="docsearch:version_rank" content="1"> <meta name="docsearch:status" content=""> <meta name="docsearch:edition" content=""> <meta name="docsearch:page_rank" content="50"> <meta name="generator" content="Antora 3.1.5"> <link rel="icon" href="../../../_/img/favicon.svg" type="image/svg+xml"> <link rel="icon" href="../../../_/img/favicon.ico" type="image/x-icon" sizes="any"> </head> <body class="article"> <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-MVPNN2" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <header class="header fixed-top"> <div class="header-top-row"> <div class="container"> <nav class="navbar navbar-expand-md flex-nowrap justify-content-between navbar-new-top"> <ul class="navbar-brand-list"> <li class="brand-logo"> <a class="navbar-brand" href="https://www.couchbase.com"> <img src="../../../_/img/couchbase-logo.svg" alt="Couchbase" /> </a> </li> <li> <a class="navbar-brand cb-documentation" href="https://docs.couchbase.com/home/index.html"> <img src="../../../_/img/cb-documentation.svg" alt="Couchbase Documentation" class="cb-docs" /> <img src="../../../_/img/cb-docs-hover.svg" alt="Couchbase Documentation" class="hide cb-hover-docs" /> </a> </li> </ul> <button class="navbar-burger" data-target="topbar-menu"> <span></span> <span></span> <span></span> </button> </nav> </div> </div> <div class="header-bottom-row" id="topbar-menu"> <div class="container"> <nav class="navbar navbar-new-bottom "> <div class="navbar-collapse collapse" id="navbar2"> <ul class="navbar-nav w-100 justify-content-start"> <li class="nav-item ""> <a href="https://docs.couchbase.com/home/index.html" class="nav-link"> <i class="fas fa-home"></i> </a> </li> <li class="nav-item "> <a class="nav-link" href="../../../home/server.html"> Server </a> </li> <li class="nav-item nav-item-selected"> <a class="nav-link" href="../../../home/mobile.html"> Mobile </a> </li> <li class="nav-item "> <a class="nav-link" href="../../../home/cloud.html"> Capella </a> </li> <li class="nav-item "> <a class="nav-link" href="../../../cloud-native-database/index.html"> Cloud-Native </a> </li> <li class="nav-item "> <a class="nav-link" href="../../../home/sdk.html"> Couchbase SDKs </a> </li> <li class="nav-item "> <a class="nav-link" href="../../../home/columnar-sdk.html"> Columnar SDKs </a> </li> </ul> </div> <div class="primary-action"> <div class="navbar-item search" id="search"> <input class="dataLayer query" type="text" placeholder="Search Docs"><i class="fas fa-search"></i> </div> <a class="btn btn-primary btn-grey-reverse" onclick="(window.dataLayer=window.dataLayer||[]).push({'event':'customEvent', 'category':'CTA', 'action':'Button Click', 'label':'Download'});" href="https://www.couchbase.com/downloads"> Downloads <i class="far fa-arrow-to-bottom fa-fw"></i> </a> <a href="https://cloud.couchbase.com/sign-up" class="btn btn-primary" onclick="(window.dataLayer=window.dataLayer||[]).push({'event':'customEvent', 'category':'CTA', 'action':'Button Click', 'label':'Free Trial'});" > Try Free <i class="far fa-cloud fa-fw"></i> </a> </div> </nav> </div> </div> </header> <div class="body container"> <aside class="nav left-sidebar"> <div class="nav-container"> <a href="#" class="menu-expand-toggle"><span>Navigation</span><i class="fas fa-times-circle"></i><i class="fas fa-chevron-circle-left"></i></a> <template id="page-versions" style="display: none"> <select class="version_list" data-component="couchbase-lite"> <option value="3.2" data-url="gs-install.html" selected>3.2</option> <option value="3.1" data-url="../../3.1/java/gs-install.html">3.1</option> <option value="3.0" data-url="../../3.0/java/gs-install.html">3.0</option> <option value="2.8" data-url="../../2.8/java/gs-install.html">2.8</option> </select> </template> </div> </aside> <aside class="toc sidebar" data-title="Contents" data-levels="2@"> <div class="sidebar-box"> <div class="tools" role="navigation"> <ul> <li class="tool edit"><a href="https://github.com/couchbaselabs/docs-couchbase-lite/edit/release/3.2/modules/java/pages/gs-install.adoc" title="Edit Page" target="_blank" rel="noopener" class="remove-ext-icon">Edit on GitHub</a></li> </ul> </div> <div class="toc-menu"></div> <div class="is-this-helpful-box"> <h4> Is this page helpful?</h4> <div class="btn-row"> <a href="#" class="like-btn helpful-btn" id="yesBtn" data-page-rating="like" > <i class="far fa-thumbs-up"></i> Yes </a> <a href="#" class="dislike-btn helpful-btn" id="noBtn" data-page-rating="dislike"> <i class="far fa-thumbs-down"></i> No</a> </div> <div class="any-feedback"> <a href="#" class="btn any-feedback-btn" id="myCustomTrigger">Leave Additional Feedback? </a> </div> <div class="dialog-box" id="dialogBox"> <form> <div class="form-group " id="additionalFeedbackBox"> <textarea class="input-control feed-back-msg" rows="8" placeholder="Any Additonal Feedback?"></textarea> <div class="action-btn-row "> <a href="#" class="skip-btn" id="skipBtnMsg">Skip</a> <button class="submit-btn btn blue-btn disabled" > Submit </button> <a href="#" class="info-btn"><i class="fas fa-info-circle"></i></a> </div> </div> </form> </div> </div> </div> </aside> <div class="feedback-modal modal-popup"> <div class="modal-popup-dialogue"> <div class="popup-header"> <a href="#" class="close-popup"><i class="fa fa-times"></i></a> </div> <div class="popup-content"> <p> Please use the form below to provide your feedback. Because your feedback is valuable to us, the information you submit in this form is recorded in our issue tracking system (JIRA), which is publicly available. You can track the status of your feedback using the ticket number displayed in the dialog once you submit the form. </p> </div> </div> </div> <main class="article" data-ceiling="topbar"> <div class="article-header"> <nav class="crumbs" aria-label="breadcrumbs"> <ul> <li class="crumb"><a href="../index.html">Couchbase Lite</a></li> <li class="crumb"><a href="quickstart.html">Java</a></li> <li class="crumb">Start Here!</li> <li class="crumb"><a href="gs-install.html">Install</a></li> </ul> </nav> </div> <article class="doc"> <div class="page-heading-title"> <h1 class="page">Couchbase Lite on Java&#8201;&#8212;&#8201;Installing</h1> <div class="labels"> <ul></ul> </div> </div> <div class="contributor-list-box"> <span class="last-commit-date" id="commitdate"> </span> <ul id="contributorList"></ul> <span id="otherContributor"> + </span> </div><div id="preamble"> <div class="sectionbody"> <div class="quoteblock abstract"> <blockquote> <div class="paragraph"> <p>Description&#8201;&#8212;&#8201;<em>Couchbase Lite on Java&#8201;&#8212;&#8201;a framework for developing offline-first Java applications for mobile and edge</em><br> <em>Abstract&#8201;&#8212;&#8201;This content provides instructions that enable you to deploy Couchbase Lite on java</em><br> Related Content&#8201;&#8212;&#8201;<a href="gs-install.html" class="xref page">Install</a> | <a href="gs-prereqs.html" class="xref page">Prerequisites</a> | <a href="gs-build.html" class="xref page">Build and Run</a></p> </div> </blockquote> </div> </div> </div> <div class="sect1"> <h2 id="introduction"><a class="anchor" href="#introduction"></a>Introduction</h2> <div class="sectionbody"> <div class="paragraph"> <p><em>Couchbase&#160;Lite</em> on Java 3.2.1 enables development and deployment of Couchbase&#160;Lite applications to a JVM environment. You can deploy Standalone (Java Desktop/Console) apps or Web Apps (using, for example, Tomcat; including embedded Tomcat deployments).</p> </div> <div class="sidebarblock"> <div class="content"> <div class="title">Quick Steps</div> <div class="paragraph"> <p>For experienced developers, this is all you need to add <em>Couchbase&#160;Lite for Java 3.2.1</em> to your application projects.</p> </div> <div id="tabs-1" class="openblock tabs is-sync is-loading"> <div class="content"> <div class="ulist tablist"> <ul> <li id="tabs-1-enterprise-edition" class="tab"> <p>Enterprise Edition</p> </li> <li id="tabs-1-community-edition" class="tab"> <p>Community Edition</p> </li> </ul> </div> <div id="tabs-1-enterprise-edition--panel" class="tabpanel" aria-labelledby="tabs-1-enterprise-edition"> <div class="paragraph"> <p>Include the following in your Gradle <code>build.gradle</code> or Maven <code>pom.xml</code> file, as appropriate:</p> </div> <div class="ulist"> <ul> <li> <p>The Couchbase Enterprise Edition repository<br> <code><a href="https://mobile.maven.couchbase.com/maven2/dev/" class="bare">https://mobile.maven.couchbase.com/maven2/dev/</a></code></p> </li> <li> <p>The Couchbase&#160;Lite Enterprise Edition dependency:<br> <code>couchbase-lite-java-ee:3.2.1</code></p> <div class="olist arabic"> <ol class="arabic"> <li> <p>If you want to use Vector Search, add the Couchbase Lite Vector Search dependency: <code>couchbase-lite-java-vector-search</code></p> </li> <li> <p>You must then use <code>CouchbaseLite.enableVectorSearch();</code> to enable the vector search extension.</p> </li> </ol> </div> </li> </ul> </div> </div> <div id="tabs-1-community-edition--panel" class="tabpanel" aria-labelledby="tabs-1-community-edition"> <div class="olist arabic"> <ol class="arabic"> <li> <p>Include the Couchbase&#160;Lite for Java dependency in your Gradle <code>build.gradle</code> or Maven <code>pom.xml</code> file, as appropriate:<br> <code>couchbase-lite-java:3.2.1</code></p> </li> <li> <p>For Gradle:<br> Check you have <code>mavenCentral()</code> in <code>repositories</code> (or in <code>settings.gradle</code>).<br> Maven automatically checks its own repo for dependencies.</p> </li> </ol> </div> </div> </div> </div> <div class="admonitionblock note"> <table> <tr> <td class="icon"> <i class="fa icon-note" title="Note"></i> </td> <td class="content"> for Linux, make sure you have followed the <a href="gs-prereqs.html#additional-steps-for-linux" class="xref page">additional steps required</a>. </td> </tr> </table> </div> </div> </div> <div class="paragraph"> <p>That&#8217;s it! You&#8217;re all set to begin developing powerful Couchbase&#160;Lite applications.</p> </div> <div class="paragraph"> <p>Now, try the <a href="gs-build.html" class="xref page">Getting Started</a> application, which demonstrates use of key CRUD functionality.</p> </div> </div> </div> <div class="sect1"> <h2 id="preparing-your-build-environment"><a class="anchor" href="#preparing-your-build-environment"></a>Preparing Your Build Environment</h2> <div class="sectionbody"> <div class="paragraph"> <p>This section shows how to set up and use <em>Couchbase&#160;Lite</em> on Java to build desktop and web applications using gradle, Maven, Tomcat and Intellij IDEA Community Edition. It assumes a familiarity with these products, however you are free to use your own choice of development tools.</p> </div> <div class="sect2"> <h3 id="binaries"><a class="anchor" href="#binaries"></a>Binaries</h3> <div class="paragraph"> <p><em>Couchbase&#160;Lite</em> on Java binaries are available for both Community (CE) and Enterprise (EE) editions from the <em>Maven</em> repositories.</p> </div> </div> <div class="sect2"> <h3 id="prerequisites"><a class="anchor" href="#prerequisites"></a>Prerequisites</h3> <div class="ulist"> <ul> <li> <p>Planning to sync with a <em>Couchbase&#160;Server</em>?</p> <div class="paragraph"> <p>You will need to have runnable instances of <em>Couchbase&#160;Server</em> and <em>Sync&#160;Gateway</em> installed. If you have not already done so see <a href="../../../sync-gateway/current/get-started-prepare.html" class="xref page">Prepare Sync Gateway</a></p> </div> </li> <li> <p>Running on Microsoft Windows?</p> <div class="paragraph"> <p>Windows requires C&#43;&#43; runtime installed. Please install the Visual C&#43;&#43; Redistribution package from this link: <a href="https://www.microsoft.com/en-us/download/details.aspx?id=52685" class="bare">https://www.microsoft.com/en-us/download/details.aspx?id=52685</a></p> </div> </li> <li> <p>Deploying to Linux?<br> You need to deploy the Couchbase&#160;Lite <code>support</code> library, which is available <em>only</em> on the zip download distributable. See the <em>Additional Steps for Linux</em> section in <a href="gs-prereqs.html#additional-steps-for-linux" class="xref page">gs-prereqs.adoc#additional-steps-for-linux</a>.</p> </li> </ul> </div> </div> </div> </div> <div class="sect1"> <h2 id="standalone-apps"><a class="anchor" href="#standalone-apps"></a>Standalone Apps</h2> <div class="sectionbody"> <div class="admonitionblock important"> <table> <tr> <td class="icon"> <i class="fa icon-important" title="Important"></i> </td> <td class="content"> <div class="paragraph"> <p>To use Vector Search, you must have Couchbase Lite installed and add the Vector Search extension to your Couchbase Lite application. Vector Search is available only for 64-bit architectures and Intel processors that support the Advanced Vector Extensions 2 (AVX2) instruction set. To verify whether your device supports the AVX2 instructions set, <a href="https://www.intel.com/content/www/us/en/support/articles/000090473/processors/intel-core-processors.html">follow these instructions.</a></p> </div> </td> </tr> </table> </div> <div class="sect2"> <h3 id="using-gradle"><a class="anchor" href="#using-gradle"></a>Using Gradle</h3> <div class="olist arabic"> <ol class="arabic"> <li> <p>Create a project folder</p> </li> <li> <p>Initialize it for a Gradle Java application</p> </li> <li> <p>Include the content shown in <a href="#ex-bgf1">Example 1</a> in your app-level <code>build.gradle</code> file</p> </li> <li> <p>Open the project folder in Intellij IDEA and import the gradle settings.</p> <div class="openblock"> <div class="content"> <div class="admonitionblock tip"> <table> <tr> <td class="icon"> <i class="fa icon-tip" title="Tip"></i> </td> <td class="content"> If you don&#8217;t have auto-import set for Gradle projects, then accept the <strong>Import Gradle Project</strong> prompt that is displayed bottom-right of the screen<br> Note the Gradle menu at the extreme right of the screen: </td> </tr> </table> </div> <div class="imageblock"> <div class="content"> <img src="_images/GradleMenuWebApp.png" alt="GradleMenuWebApp" width="300"> </div> </div> </div> </div> </li> </ol> </div> <div class="paragraph"> <p>That&#8217;s it. You&#8217;re all set to start building your own <em>Couchbase&#160;Lite</em> on Java applications&#8201;&#8212;&#8201;see <a href="gs-build.html" class="xref page">Build and Run</a> for an example of how to do that.</p> </div> <div id="ex-bgf1" class="exampleblock"> <div class="title">Example 1. build.gradle file content</div> <div class="content"> <div id="tabs-2" class="openblock tabs is-sync is-loading"> <div class="content"> <div class="ulist tablist"> <ul> <li id="tabs-2-enterprise-edition" class="tab"> <p>Enterprise Edition</p> </li> <li id="tabs-2-vector-search-extension" class="tab"> <p>Vector Search Extension</p> </li> <li id="tabs-2-community-edition" class="tab"> <p>Community edition</p> </li> </ul> </div> <div id="tabs-2-enterprise-edition--panel" class="tabpanel" aria-labelledby="tabs-2-enterprise-edition"> <div class="listingblock"> <div class="title">Compile options</div> <div class="content"> <pre class="highlightjs highlight"><code class="language-groovy hljs" data-lang="groovy">// Required only if your project has some Kotlin source code kotlinOptions { jvmTarget = '11' } // Set minimum JVM level to ensure availability of, for example, lambda expressions compileOptions { targetCompatibility JavaVersion.VERSION_11 sourceCompatibility JavaVersion.VERSION_11 // ... other section content as required by user }</code></pre> </div> </div> <div class="listingblock"> <div class="title">Dependencies</div> <div class="content"> <pre class="highlightjs highlight"><code class="language-groovy hljs" data-lang="groovy">dependencies { implementation "com.couchbase.lite:couchbase-lite-java:3.2.1" // ... other section content as required by user }</code></pre> </div> </div> <div class="listingblock"> <div class="title">Repositories</div> <div class="content"> <pre class="highlightjs highlight"><code class="language-groovy hljs" data-lang="groovy">repositories { maven {url 'https://mobile.maven.couchbase.com/maven2/dev/'} // ... other section content as required by user }</code></pre> </div> </div> </div> <div id="tabs-2-vector-search-extension--panel" class="tabpanel" aria-labelledby="tabs-2-vector-search-extension"> <div class="admonitionblock note"> <table> <tr> <td class="icon"> <i class="fa icon-note" title="Note"></i> </td> <td class="content"> Vector Search is an <strong>Enterprise-only</strong> feature. </td> </tr> </table> </div> <div class="openblock"> <div class="content"> <div class="listingblock"> <div class="title">Compile options</div> <div class="content"> <pre class="highlightjs highlight"><code class="language-groovy hljs" data-lang="groovy">// Required only if your project has some Kotlin source code kotlinOptions { jvmTarget = '11' } // Set minimum JVM level to ensure availability of, for example, lambda expressions compileOptions { targetCompatibility JavaVersion.VERSION_11 sourceCompatibility JavaVersion.VERSION_11 // ... other section content as required by user }</code></pre> </div> </div> <div class="listingblock"> <div class="title">Dependencies</div> <div class="content"> <pre class="highlightjs highlight"><code class="language-groovy hljs" data-lang="groovy">dependencies { implementation "com.couchbase.lite:couchbase-lite-java:3.2.1" // All standard 64-bit ARM architectures implementation 'com.couchbase.lite:couchbase-lite-java-vector-search-arm64-1.0.0' // ... other section content as required by user }</code></pre> </div> </div> <div class="listingblock"> <div class="title">Repositories</div> <div class="content"> <pre class="highlightjs highlight"><code class="language-groovy hljs" data-lang="groovy">repositories { maven {url 'https://mobile.maven.couchbase.com/maven2/dev/'} google() mavenCentral() // ... other section content as required by user }</code></pre> </div> </div> <div class="listingblock"> <div class="title">Activating the Extension</div> <div class="content"> <pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java" data-source-url="https://github.com/couchbaselabs/docs-couchbase-lite/blob/2e90b8dcc24996447949e742017429090850b253/modules/java/examples/snippets/common/main/java/com/couchbase/codesnippets/VectorSearchExamples.java"> try { CouchbaseLite.enableVectorSearch(); } catch (CouchbaseLiteException e) { throw new IllegalStateException("Could not enable vector search", e); }</code></pre> </div> </div> </div> </div> </div> <div id="tabs-2-community-edition--panel" class="tabpanel" aria-labelledby="tabs-2-community-edition"> <div class="listingblock"> <div class="title">Compile options</div> <div class="content"> <pre class="highlightjs highlight"><code class="language-groovy hljs" data-lang="groovy">// Required only if your project has some Kotlin source code kotlinOptions { jvmTarget = '11' } // Set minimum JVM level to ensure availability of, for example, lambda expressions compileOptions { targetCompatibility JavaVersion.VERSION_11 sourceCompatibility JavaVersion.VERSION_11 // ... other section content as required by user }</code></pre> </div> </div> <div class="listingblock"> <div class="title">Dependencies</div> <div class="content"> <pre class="highlightjs highlight"><code class="language-groovy hljs" data-lang="groovy">dependencies { implementation "com.couchbase.lite:couchbase-lite-java:3.2.1" // ... other section content as required by user }</code></pre> </div> </div> </div> </div> </div> </div> </div> </div> <div class="sect2 include-in-toc"> <h3 id="using-maven"><a class="anchor" href="#using-maven"></a>Using Maven</h3> <div class="olist arabic"> <ol class="arabic"> <li> <p>Include the content shown in <a href="#ex-bmf1">Example 2</a> in your <code>pom.xml</code> file in the root of your project folder</p> </li> <li> <p>That&#8217;s it&#8201;&#8212;&#8201;just add your own code</p> </li> </ol> </div> <div class="paragraph"> <p>You&#8217;re all set to start building your own <em>Couchbase&#160;Lite</em> on Java applications&#8201;&#8212;&#8201;see <a href="gs-build.html" class="xref page">Build and Run</a> for an example of how to do that.</p> </div> <div id="ex-bmf1" class="exampleblock"> <div class="title">Example 2. pom.xml file content</div> <div class="content"> <div id="tabs-3" class="openblock tabs is-sync is-loading"> <div class="content"> <div class="ulist tablist"> <ul> <li id="tabs-3-enterprise-edition" class="tab"> <p>Enterprise Edition</p> </li> <li id="tabs-3-community-edition" class="tab"> <p>Community edition</p> </li> </ul> </div> <div id="tabs-3-enterprise-edition--panel" class="tabpanel" aria-labelledby="tabs-3-enterprise-edition"> <div class="listingblock"> <div class="title">Compile properties</div> <div class="content"> <pre class="highlightjs highlight"><code class="language-XML hljs" data-lang="XML">&lt;properties&gt; &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt; &lt;maven.compiler.source&gt;11&lt;/maven.compiler.source&gt; &lt;maven.compiler.target&gt;11&lt;/maven.compiler.target&gt; &lt;/properties&gt;</code></pre> </div> </div> <div class="listingblock"> <div class="title">Dependencies</div> <div class="content"> <pre class="highlightjs highlight"><code class="language-XML hljs" data-lang="XML">&lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;com.couchbase.lite&lt;/groupId&gt; &lt;artifactId&gt;couchbase-lite-java-ee&lt;/artifactId&gt; &lt;version&gt;3.2.1&lt;/version&gt; &lt;/dependency&gt; &lt;!-- ... any other section content as required by user-home --&gt; &lt;/dependencies&gt;</code></pre> </div> </div> <div class="listingblock"> <div class="title">Repositories</div> <div class="content"> <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml">&lt;repositories&gt; &lt;repository&gt; &lt;id&gt;couchbase&lt;/id&gt; &lt;url&gt;https://mobile.maven.couchbase.com/maven2/dev/&lt;/url&gt; &lt;/repository&gt; // ... any other section content as required by user &lt;/repositories&gt;</code></pre> </div> </div> </div> <div id="tabs-3-community-edition--panel" class="tabpanel" aria-labelledby="tabs-3-community-edition"> <div class="listingblock"> <div class="title">Compile properties</div> <div class="content"> <pre class="highlightjs highlight"><code class="language-XML hljs" data-lang="XML">&lt;properties&gt; &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt; &lt;maven.compiler.source&gt;11&lt;/maven.compiler.source&gt; &lt;maven.compiler.target&gt;11&lt;/maven.compiler.target&gt; &lt;/properties&gt;</code></pre> </div> </div> <div class="listingblock"> <div class="title">Dependencies</div> <div class="content"> <pre class="highlightjs highlight"><code class="language-xml hljs" data-lang="xml">&lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;com.couchbase.lite&lt;/groupId&gt; &lt;artifactId&gt;couchbase-lite-java&lt;/artifactId&gt; &lt;version&gt;3.2.1&lt;/version&gt; &lt;/dependency&gt; // ... any other section content as required by user &lt;/dependencies&gt;</code></pre> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> <div class="sect1"> <h2 id="web-app-development"><a class="anchor" href="#web-app-development"></a>Web App Development</h2> <div class="sectionbody"> <div class="paragraph"> <p>This section explains how to set-up a build project to create <em>Couchbase&#160;Lite</em> on Java web apps using gradle and Intellij IDEA.</p> </div> <div class="admonitionblock tip"> <table> <tr> <td class="icon"> <i class="fa icon-tip" title="Tip"></i> </td> <td class="content"> <div class="title">Using Maven</div> <div class="paragraph"> <p>For examples of how to do this using Maven POM files, see&#8201;&#8212;&#8201;</p> </div> <div class="ulist"> <ul> <li> <p><a href="https://github.com/couchbaselabs/mobile-travel-sample/tree/master/java/TravelSample">Couchbase Mobile Workshop</a></p> </li> <li> <p><a href="https://github.com/couchbaselabs/mobile-training-todo/tree/release/lithium/java-ws/server/Todo">Mobile Training To Do App</a></p> </li> </ul> </div> </td> </tr> </table> </div> <div class="sect2"> <h3 id="tomcat"><a class="anchor" href="#tomcat"></a>Tomcat</h3> <div class="paragraph"> <p>In our examples here we build and deploy web apps using a gradle plugin based on the <code>com.bmuschko.tomcat</code> plugin. It provides a simple Tomcat harness that can be used from within Intellij IDEA or the command-line&#8201;&#8212;&#8201;see <a href="#lbl-tomcat">Embedded Tomcat</a></p> </div> </div> <div class="sect2"> <h3 id="bmkMultCblJapps"><a class="anchor" href="#bmkMultCblJapps"></a>Multiple Web Apps</h3> <div class="paragraph"> <p>Each web application has its own *class loader (WebappX). This loads the classes, jars, and resources found in the application&#8217;s <code>WEB-INF/classes</code> and <code>WEB-INF/lib</code> folders, together with any shared jar files from <code>$CATALINA_BASE/lib</code>&#8201;&#8212;&#8201;see <a href="https://tomcat.apache.org/tomcat-9.0-doc/class-loader-howto.html">tomcat documentation</a> for more.</p> </div> <div class="paragraph"> <p>So, if you are running multiple Couchbase&#160;Lite web applications, deploy your <em>Couchbase&#160;Lite</em> on Java library <code>&lt;pathToCbl&gt;/libs</code> to <code>$CATALINA_BASE/lib</code>. This means you do not need to deploy it in each web app and <strong>minimizes the size of each app</strong>.</p> </div> <div class="admonitionblock note"> <table> <tr> <td class="icon"> <i class="fa icon-note" title="Note"></i> </td> <td class="content"> Configuring Couchbase&#160;Lite logging functionality will affect the logging of all web applications as the <em>common class loader</em> shares <em>Couchbase&#160;Lite Console, File</em> and <em>Custom logging functionalities</em> across all web apps. </td> </tr> </table> </div> <div class="paragraph"> <p>For information about building a WAR file see <a href="#lbl-war">Deploying a WAR File</a></p> </div> </div> <div class="sect2"> <h3 id="prerequisites-2"><a class="anchor" href="#prerequisites-2"></a>Prerequisites</h3> <div class="ulist"> <ul> <li> <p>Ensure your build environment matches the runtime Tomcat environment. Specifically, that the Java and Tomcat versions are the same.</p> </li> <li> <p>If your Tomcat server runs Linux, declare the <em>shared libraries</em> (<code>&lt;pathToCbl&gt;/support</code>) in the <code>$CATALINA_HOME/bin/setenv.sh</code> script file&#8201;&#8212;&#8201;see: <em>Additional Steps for Linux</em> section in <a href="gs-prereqs.html" class="xref page">Prerequisites</a>.</p> </li> <li> <p>Ensure the Couchbase&#160;Lite jars (<code>&lt;pathToCbl&gt;/lib</code>) are on the executable path within Tomcat&#8201;&#8212;&#8201;see: <a href="#bmkMultCblJapps">Multiple Web Apps</a></p> <div class="admonitionblock tip"> <table> <tr> <td class="icon"> <i class="fa icon-tip" title="Tip"></i> </td> <td class="content"> This also means you should declare the dependencies as <code>providedCompile</code> to avoid them being bundled into the <code>WEB-INF/libs</code> folder </td> </tr> </table> </div> </li> </ul> </div> </div> <div class="sect2"> <h3 id="steps"><a class="anchor" href="#steps"></a>Steps</h3> <div class="olist arabic"> <ol class="arabic"> <li> <p>Create a project folder and initialize it for a Gradle Java application</p> <div class="listingblock"> <div class="content"> <pre class="highlightjs highlight"><code class="language-bashrc hljs" data-lang="bashrc">gradle init</code></pre> </div> </div> </li> <li> <p>Create your <code>build.gradle</code> file, including the <a href="#ex-bgf2">Example 3</a> in your app-level build.gradle:</p> </li> <li> <p>Open the project folder in Intellij IDEA and import the gradle settings.</p> </li> </ol> </div> <div class="admonitionblock tip"> <table> <tr> <td class="icon"> <i class="fa icon-tip" title="Tip"></i> </td> <td class="content"> If you don&#8217;t have auto-import set for Gradle projects, then accept the <strong>Import Gradle Project</strong> prompt that is displayed bottom-right of the screen.<br> Note the Gradle menu at the extreme right of the screen:<br> image::GradleMenuWebApp.png[,300] </td> </tr> </table> </div> <div class="paragraph"> <p>If you want to deploy your app to a local tomcat container then see <a href="#Deploying a WAR file to tomcat">[Deploying a WAR file to tomcat]</a></p> </div> <div class="paragraph"> <p>That&#8217;s it. You&#8217;re all set to start building your own <em>Couchbase&#160;Lite</em> on Java applications&#8201;&#8212;&#8201;see <a href="gs-build.html" class="xref page">Building a Getting Started App</a> for an example of how to do that.</p> </div> <div id="ex-bgf2" class="exampleblock"> <div class="title">Example 3. build.gradle file content</div> <div class="content"> <div id="tabs-4" class="openblock tabs is-sync is-loading"> <div class="content"> <div class="ulist tablist"> <ul> <li id="tabs-4-community" class="tab"> <p>Community</p> </li> <li id="tabs-4-enterprise" class="tab"> <p>Enterprise</p> </li> </ul> </div> <div id="tabs-4-community--panel" class="tabpanel" aria-labelledby="tabs-4-community"> <div class="listingblock"> <div class="content"> <pre class="highlightjs highlight"><code class="language-groovy hljs" data-lang="groovy">dependencies { implementation "com.couchbase.lite:couchbase-lite-java:3.2.1" // ... other section content as required by user }</code></pre> </div> </div> </div> <div id="tabs-4-enterprise--panel" class="tabpanel" aria-labelledby="tabs-4-enterprise"> <div class="listingblock"> <div class="content"> <pre class="highlightjs highlight"><code class="language-groovy hljs" data-lang="groovy">repositories { maven {url 'https://mobile.maven.couchbase.com/maven2/dev/'} // ... other section content as required by user } dependencies { implementation "com.couchbase.lite:couchbase-lite-java-ee:3.2.1" // ... other section content as required by user }</code></pre> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> <div class="sect1"> <h2 id="lbl-tomcat"><a class="anchor" href="#lbl-tomcat"></a>Embedded Tomcat</h2> <div class="sectionbody"> <div class="paragraph"> <p>The simplest way to build and deploy your <em>Couchbase&#160;Lite</em> on Java web app is to use a gradle plugin that provides a simple Tomcat harness.</p> </div> <div class="paragraph"> <p>Our examples are based on the <code>com.bmuschko.tomcat</code> plugin&#8201;&#8212;&#8201;see <a href="https://github.com/bmuschko/gradle-tomcat-plugin">com.bmuschko.tomcat on Github</a>.</p> </div> <div class="paragraph"> <p>Including the plugin in your <code>build.gradle</code> file make a number of tomcat tasks available to you. View them using:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">./gradlew tasks</code></pre> </div> </div> <div class="paragraph"> <p>This shows that the following web application tasks are now available:</p> </div> <div class="ulist"> <ul> <li> <p><code>tomcatJasper</code> - Runs the JSP compiler and turns JSP pages into Java source.</p> </li> <li> <p><code>tomcatRun</code> - Uses your files as and where they are and deploys them to Tomcat.</p> </li> <li> <p><code>tomcatRunWar</code> - Assembles the web app into a war and deploys it to Tomcat.</p> </li> <li> <p><code>tomcatStop</code> - Stops Tomcat.</p> </li> </ul> </div> <div class="paragraph"> <p>So, to run the app use:</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">./gradlew tomcatRun</code></pre> </div> </div> </div> </div> <div class="sect1"> <h2 id="lbl-war"><a class="anchor" href="#lbl-war"></a>Deploying a WAR File</h2> <div class="sectionbody"> <div class="paragraph"> <p>To deploy your web app to a local Tomcat instance you need to generate a WAR file. However, you should note that when creating a war file, if you use the <code>implementation</code> dependency type then your <em>Couchbase&#160;Lite</em> jar files will be bundled into WEB-INF/lib of the web application. To exclude Couchbase&#160;Lite jar files from getting bundled and to use Couchbase&#160;Lite in multiple web applications, change the dependency type from <strong><code>implementation</code></strong> to <strong><code>providedCompile</code></strong></p> </div> <div class="olist arabic"> <ol class="arabic"> <li> <p>You can do this using the Gradle command below from within your project folder:</p> <div class="listingblock"> <div class="content"> <pre class="highlightjs highlight"><code class="language-bashrc hljs" data-lang="bashrc">./gradlew war</code></pre> </div> </div> <div class="admonitionblock note"> <table> <tr> <td class="icon"> <i class="fa icon-note" title="Note"></i> </td> <td class="content"> The generated war file will be at &lt;PROJECT ROOT&gt;/build/libs. </td> </tr> </table> </div> </li> <li> <p>Deploy the war file to Tomcat, by copying it to $CATALINA_BASE/webapps</p> <div class="admonitionblock tip"> <table> <tr> <td class="icon"> <i class="fa icon-tip" title="Tip"></i> </td> <td class="content"> You can also use Tomcat鈥檚 Manager App to deploy the war file&#8201;&#8212;&#8201;see <a href="https://tomcat.apache.org/tomcat-9.0-doc/manager-howto.html">Tomcat&#8217;s Manager App</a> documentation for more detail. </td> </tr> </table> </div> </li> <li> <p>To use common class loader approach to load Couchbase&#160;Lite libraries, copy all of the Couchbase&#160;Lite jar files in $CATALINA_BASE/lib.</p> <div class="admonitionblock note"> <table> <tr> <td class="icon"> <i class="fa icon-note" title="Note"></i> </td> <td class="content"> For linux platform see also&#8201;&#8212;&#8201;<em>Using Native Libraries for Linux</em> in <a href="gs-prereqs.html" class="xref page">Prerequisites</a> </td> </tr> </table> </div> </li> </ol> </div> </div> </div> <div class="sect1"> <h2 id="related-content"><a class="anchor" href="#related-content"></a>Related Content</h2> <div class="sectionbody"> <div class="card-row three-column-row"> <div class="sect5 column"> <h6 id=""><a class="anchor" href="#"></a></h6> <div class="ulist"> <div class="title">How to . . .</div> <ul> <li> <p><a href="gs-prereqs.html" class="xref page">Prerequisites</a></p> </li> <li> <p><a href="gs-install.html" class="xref page">Install</a></p> </li> <li> <p><a href="gs-build.html" class="xref page">Build and Run</a></p> </li> </ul> </div> </div> <div class="sect5 column"> <h6 id="-2"><a class="anchor" href="#-2"></a></h6> <div class="ulist"> <div class="title">Learn more . . .</div> <ul> <li> <p><a href="database.html" class="xref page">Databases</a></p> </li> <li> <p><a href="document.html" class="xref page">Documents</a></p> </li> <li> <p><a href="blob.html" class="xref page">Blobs</a></p> </li> <li> <p><a href="replication.html" class="xref page">Remote Sync Gateway</a></p> </li> <li> <p><a href="conflict.html" class="xref page">Handling Data Conflicts</a></p> </li> </ul> </div> </div> <div class="sect5 column"> <h6 id="-3"><a class="anchor" href="#-3"></a></h6> <div class="paragraph"> <div class="title">Dive Deeper . . .</div> <p><a href="https://forums.couchbase.com/c/mobile/14">Mobile Forum</a> | <a href="https://blog.couchbase.com/">Blog</a> | <a href="https://docs.couchbase.com/tutorials/">Tutorials</a></p> </div> </div> </div> </div> </div> </article> </main> </div> <footer class="footer"> <div class="container"> <div class="footer-links"> <div class="col"> <div class="footer-logo"> <a href="https://www.couchbase.com" class="icon"> <img src="../../../_/img/couchbase-logo.svg" alt="Couchbase"> </a> </div> </div> <div class="col"> <ul> <li><a href="https://docs.couchbase.com" target="_blank" rel="noopener">Documentation</a></li> <li><a href="https://forums.couchbase.com" target="_blank" rel="noopener">Forums</a></li> <li><a href="https://support.couchbase.com" target="_blank" rel="noopener">Support</a></li> </ul> </div> <div class="col"> <ul> <li><a href="https://developer.couchbase.com" target="_blank" rel="noopener">Developer Portal</a></li> <li><a href="https://blog.couchbase.com" target="_blank" rel="noopener">Blog</a></li> <li><a href="https://www.couchbase.com/resources">Resources</a></li> </ul> </div> <div class="col"> <ul> <li><a href="https://www.couchbase.com/get-started-developing-nosql">Get Started</a></li> <li><a href="https://www.couchbase.com/downloads">Downloads</a></li> <li><a href="https://learn.couchbase.com/store?utf8=%E2%9C%93&ss=1&ct=78327&commit=Filter" target="_blank" rel="noopener">Training</a></li> </ul> </div> <div class="col"> <ul class="social-icons"> <li> <svg width="14" height="14" viewBox="0 0 32.1 26.1"> <path id="twitter" class="cls-1" d="M32,7.1a11.836,11.836,0,0,1-3.8,1,6.462,6.462,0,0,0,2.9-3.6,12.606,12.606,0,0,1-4.2,1.6A6.492,6.492,0,0,0,22.1,4a6.594,6.594,0,0,0-6.6,6.6,7.719,7.719,0,0,0,.2,1.5A18.458,18.458,0,0,1,2.2,5.2a6.294,6.294,0,0,0-.9,3.3A6.765,6.765,0,0,0,4.2,14a6.109,6.109,0,0,1-3-.8v.1a6.543,6.543,0,0,0,5.3,6.4,4.678,4.678,0,0,1-1.7.2,4.869,4.869,0,0,1-1.2-.1,6.679,6.679,0,0,0,6.1,4.6,12.917,12.917,0,0,1-8.2,2.8,9.151,9.151,0,0,1-1.6-.1,18.438,18.438,0,0,0,10.1,3c12.1,0,18.7-10,18.7-18.7v-.8A13.336,13.336,0,0,0,32,7.2Z" transform="translate(0.1 -4)"/></svg> <a href="https://twitter.com/couchbase" class="icon"> Twitter </a> </li> <li> <svg width="14" height="14" viewBox="0 0 32 32"> <path id="linkedin" class="cls-1" d="M29,0H3A3.076,3.076,0,0,0,0,3V29a3.009,3.009,0,0,0,3,3H29a2.946,2.946,0,0,0,3-3V3A3.009,3.009,0,0,0,29,0ZM12,26H8V12h4ZM10,10a2,2,0,1,1,2-2A2.006,2.006,0,0,1,10,10ZM26,26H22V18a2,2,0,0,0-4,0v8H14V12h4v2.5c.8-1.1,2.1-2.5,3.5-2.5A4.736,4.736,0,0,1,26,17Z"/></svg> <a href="https://www.linkedin.com/company/couchbase" class="icon"> Linkedin </a> </li> <li> <svg width="14" height="14" viewBox="0 0 32 32"> <path id="facebook" class="cls-1" d="M29,0H3A2.652,2.652,0,0,0,0,3V29a2.652,2.652,0,0,0,3,3H16V18H12V14h4V12a6.452,6.452,0,0,1,6-6h4v4H22a2.151,2.151,0,0,0-2,2v2h6l-1,4H20V32h9a2.652,2.652,0,0,0,3-3V3A2.652,2.652,0,0,0,29,0Z"/></svg> <a href="https://www.facebook.com/Couchbase" class="icon"> Facebook </a> </li> </ul> </div> </div> <div class="footer-terms"> <div class="footer-terms-copyright"> <span>漏 2024 Couchbase and the Couchbase logo are registered trademarks of Couchbase, Inc. All third party trademarks (including logos and icons) referenced by Couchbase, Inc. remain the property of their respective owners. </span> </div> <div class="footer-terms-links"> <a href="https://www.couchbase.com/terms-of-use">Terms of Use</a> <a href="https://www.couchbase.com/privacy-policy">Privacy Policy</a> <a href="https://www.couchbase.com/cookie-policy">Cookie Policy</a> <a href="https://www.couchbase.com/support-policy">Support Policy</a> <a href="https://info.couchbase.com/unsubscribe-or-manage-preferences.html" target="_blank" rel="noopener">Marketing Preference Center</a> </div> </div> </div> </footer> <script src="../../../_/js/site-navigation-data.js"></script> <script id="page-navigation-group" type="application/json"> {"title":"Mobile","components":["couchbase-lite","sync-gateway"],"url":"/home/mobile.html","latestVersions":{"couchbase-lite":"3.2","sync-gateway":"3.2"}} </script> <template id="run-code-panel"> <div class="action-panel"> <form class="action-panel-control" method="POST" action="https://couchbase.live/run" target="run-code-output"> <input type="hidden" name="lang"> <input type="hidden" name="code"> <input type="hidden" name="from" value="docs"> <div class="controls"> <button class="control-button rerun" type="submit"><i class="fas fa-redo"></i></button> <span class="shell-name control-label">Output</span> <button class="control-button close"><i class="fas fa-times"></i> Close</button> </div> </form> <iframe class="run-code-output" name="run-code-output"></iframe> </div> </template> <script id="site-script" src="../../../_/js/vendor/chatbox-ui.js"></script> <script id="site-script" src="../../../_/js/site.js"></script> <script async src="../../../_/js/vendor/tabs.js" data-sync-storage-key="preferred-tab"></script> <script defer src="../../../_/js/vendor/fontawesome-icon-defs.js"></script> <script defer src="../../../_/js/vendor/fontawesome.js" data-search-pseudo-elements="true"></script> <script async src="../../../_/js/vendor/highlight.js"></script> <script async id="search-script" src="../../../_/js/vendor/docsearch.js" data-app-id="NI1G57N08Q" data-api-key="d3eff3e8bcc0860b8ceae87360a47d54" data-index-name="prod_docs_couchbase" data-stylesheet="../../../_/css/vendor/docsearch.css"></script> <script async id="feedback-script" src="../../../_/js/vendor/feedback.js?v=1" data-collector-id="709818cb"></script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10