6 Running the Coherence Examples

Coherence guides and tutorials are now hosted on the Coherence GitHub Repository and are documented here: Examples - Guides & Tutorials Overview. These examples can be run against both Coherence 14.1.1.2206.x Feature Pack versions and Coherence Community Edition (CE) versions 22.06 and above.

Note:

In the rest of the document, examples refer to both guides and tutorials.

This chapter includes the following sections:

About Coherence Examples

There are two subsets of examples: Guides and Tutorials.

Guides - These simple guides are designed to be a quick hands-on introduction to a specific feature of Coherence. In most cases, they require nothing more than a Coherence jar and an IDE (or a text editor if you are old-school). Guides are typically built as a combination of Maven and Gradle project, including the corresponding wrappers for those tools, making them simple to build as stand-alone projects without needing to build the whole Coherence source tree.

Tutorials - These tutorials provide a deeper understanding of larger Coherence features and concepts that cannot usually be explained with a few simple code snippets. They might, for example, require a running Coherence cluster to properly show a feature. Tutorials are typically built as a combination of Maven and Gradle project, including the corresponding wrappers for those tools, making them simple to build as stand-alone projects without needing to build the whole Coherence source tree.

Obtaining the Examples

The examples are hosted on the Coherence Community Edition GitHub repository. See Oracle Coherence Community Edition.
In a directory of your choice, clone the examples using the following:
git clone https://github.com/oracle/coherence.git

This command clones the examples into a directory called coherence, off the current directory. You can find the examples in the prj/examples sub-directory.

The documentation for the examples is available online. See Examples - Guides & Tutorials Overview.

Prerequisites

Each example has documentation outlining the prerequisites for building and running the specific example.
As a minimum, you will require the following:
  • JDK11
  • Maven 3.8+ or Gradle 4+. See Maven and Gradle.
  • You can also import the code straight into your IDE such as IntelliJ IDEA.

Building and Running the Examples

The way to build and run the examples depends on whether you are running the examples against the Community Edition (CE) or the Coherence 14.1.1.2206 Feature Pack release.

Running Example Using the Coherence Community Edition

Perform the following steps to run examples using Coherence Community Edition (CE):
  1. Navigate to the coherence directory you have cloned.
  2. Checkout the tag for the CE version you are using (required only once for all examples). For example, for 22.06, use:
    git checkout v22.06
  3. Follow the documentation for the specific example you want to run.

Running Examples Using Coherence 14.1.1.2206 Feature Pack

This section includes the following topics:

Installing the Prerequisites

After you have installed the Feature Pack, you must install the required Coherence Maven poms and jars to run the examples. This step is required only once.

Set the COHERENCE_HOME environment variable to the coherence directory under your installation directory. For example, if Coherence is installed in the /u01/coherenceHome location, then COHERENCE_HOME=/u01/coherenceHome/coherence.

Run the following commands to install the various artifacts which are the minimum requirements for most of the examples.

Note:

You can also use the maven-sync plug-in to install all artifacts. See Introduction to the Maven Synchronization Plug-In in Developing Applications Using Continuous Integration.
For Linux/Mac:
mvn install:install-file  -Dpackaging=pom -Dfile=$COHERENCE_HOME/plugins/maven/com/oracle/coherence/coherence-bom/14.1.1/coherence-bom.14.1.1.pom \
    -DpomFile=$COHERENCE_HOME/plugins/maven/com/oracle/coherence/coherence-bom/14.1.1/coherence-bom.14.1.1.pom

mvn install:install-file -Dfile=$COHERENCE_HOME/lib/coherence.jar \
    -DpomFile=$COHERENCE_HOME/plugins/maven/com/oracle/coherence/coherence/14.1.1/coherence.14.1.1.pom

mvn install:install-file -Dfile=$COHERENCE_HOME/lib/coherence-bedrock.jar \
    -DpomFile=$COHERENCE_HOME/plugins/maven/com/oracle/coherence/coherence-bedrock/14.1.1/coherence-bedrock.14.1.1.pom

mvn install:install-file -Dfile=$COHERENCE_HOME/lib/coherence-bedrock-testing-support.jar \
    -DpomFile=$COHERENCE_HOME/plugins/maven/com/oracle/coherence/coherence-bedrock-testing-support/14.1.1/coherence-bedrock-testing-support.14.1.1.pom

mvn install:install-file -Dfile=$COHERENCE_HOME/lib/coherence-grpc.jar \
    -DpomFile=$COHERENCE_HOME/plugins/maven/com/oracle/coherence/coherence-grpc/14.1.1/coherence-grpc.14.1.1.pom

mvn install:install-file -Dfile=$COHERENCE_HOME/lib/coherence-grpc-proxy.jar \
    -DpomFile=$COHERENCE_HOME/plugins/maven/com/oracle/coherence/coherence-grpc-proxy/14.1.1/coherence-grpc-proxy.14.1.1.pom
    
mvn install:install-file -Dfile=$COHERENCE_HOME/lib/coherence-java-client.jar \
    -DpomFile=$COHERENCE_HOME/plugins/maven/com/oracle/coherence/coherence-java-client/14.1.1/coherence-java-client.14.1.1.pom
            
mvn install:install-file -Dfile=$COHERENCE_HOME/lib/coherence-json.jar \
    -DpomFile=$COHERENCE_HOME/plugins/maven/com/oracle/coherence/coherence-json/14.1.1/coherence-json.14.1.1.pom
Required for GraphQL:
mvn install:install-file -Dfile=$COHERENCE_HOME/lib/coherence-cdi-server.jar \
    -DpomFile=$COHERENCE_HOME/plugins/maven/com/oracle/coherence/coherence-cdi-server/14.1.1/coherence-cdi-server.14.1.1.pom

mvn install:install-file -Dfile=$COHERENCE_HOME/lib/coherence-cdi.jar \
    -DpomFile=$COHERENCE_HOME/plugins/maven/com/oracle/coherence/coherence-cdi/14.1.1/coherence-cdi.14.1.1.pom
For Windows:
mvn install:install-file  -Dpackaging=pom -Dfile=%COHERENCE_HOME%\plugins\maven\com\oracle\coherence\coherence-bom\14.1.1\coherence-bom.14.1.1.pom ^
    -DpomFile=%COHERENCE_HOME%\plugins\maven\com\oracle\coherence\coherence-bom\14.1.1\coherence-bom.14.1.1.pom

mvn install:install-file -Dfile=%COHERENCE_HOME%\lib\coherence.jar ^
    -DpomFile=%COHERENCE_HOME%\plugins\maven\com\oracle\coherence\coherence\14.1.1\coherence.14.1.1.pom

mvn install:install-file -Dfile=%COHERENCE_HOME%\lib\coherence-bedrock.jar ^
    -DpomFile=%COHERENCE_HOME%\plugins\maven\com\oracle\coherence\coherence-bedrock\14.1.1\coherence-bedrock.14.1.1.pom

mvn install:install-file -Dfile=%COHERENCE_HOME%\lib\coherence-bedrock-testing-support.jar ^
    -DpomFile=%COHERENCE_HOME%\plugins\maven\com\oracle\coherence\coherence-bedrock-testing-support\14.1.1\coherence-bedrock-testing-support.14.1.1.pom

mvn install:install-file -Dfile=%COHERENCE_HOME%\lib\coherence-grpc.jar ^
    -DpomFile=%COHERENCE_HOME%\plugins\maven\com\oracle\coherence\coherence-grpc\14.1.1\coherence-grpc.14.1.1.pom

mvn install:install-file -Dfile=%COHERENCE_HOME%\lib\coherence-grpc-proxy.jar ^
    -DpomFile=%COHERENCE_HOME%\plugins\maven\com\oracle\coherence\coherence-grpc-proxy\14.1.1\coherence-grpc-proxy.14.1.1.pom

mvn install:install-file -Dfile=%COHERENCE_HOME%\lib\coherence-java-client.jar ^
    -DpomFile=%COHERENCE_HOME%\plugins\maven\com\oracle\coherence\coherence-java-client\14.1.1\coherence-java-client.14.1.1.pom

mvn install:install-file -Dfile=%COHERENCE_HOME%\lib\coherence-json.jar ^
    -DpomFile=%COHERENCE_HOME%\plugins\maven\com\oracle\coherence\coherence-json\14.1.1\coherence-json.14.1.1.pom
Required for GraphQL:
mvn install:install-file -Dfile=%COHERENCE_HOME%\lib\coherence-cdi-server.jar ^
    -DpomFile=%COHERENCE_HOME%\plugins\maven\com\oracle\coherence\coherence-cdi-server\14.1.1\coherence-cdi-server.14.1.1.pom

mvn install:install-file -Dfile=%COHERENCE_HOME%\lib\coherence-cdi.jar ^
    -DpomFile=%COHERENCE_HOME%\plugins\maven\com\oracle\coherence\coherence-cdi\14.1.1\coherence-cdi.14.1.1.pom
Building and Running Any Example

To run any of the examples, you must change the group id and revision using the -D option in mvnw or the -P option in gradlew commands to set the Coherence version and group ID you are using.

Examples are shown below:

Maven:
./mvnw -Dcoherence.group.id=com.oracle.coherence -Drevision=14.1.1-2206-1 clean verify
Gradle:
./gradlew -PcoherenceGroupId=com.oracle.coherence -PcoherenceVersion=14.1.1-2206-1 clean build