11 Building Oracle Coherence Projects with Maven

You can use the Oracle Coherence archetypes to create, build, and deploy Oracle Coherence applications.

Topics:

11.1 Introduction to Building Oracle Coherence Projects with Maven

Oracle Fusion Middleware provides a Maven plug-in and an archetype is provided for Oracle Coherence Grid Archive (GAR) projects.

Table 11-1 describes the Maven coordinates.

Table 11-1 Maven Coordinates with Coherence

artifacts groupId artifactId version

GAR Plugin

com.oracle.coherence

gar-maven-plugin

12.2.1-0-0

GAR Archetype

com.oracle.coherence.archetype

gar-maven-archetype

12.2.1-0-0

Table 11-2 describes the goals supported by the Oracle Coherence plug-in.

Table 11-2 Oracle Coherence Goals

Goal Purpose

generate-descriptor

Generates the project's POF configuration file.

package

Packages the basic GAR assets, including library dependencies into a JAR archive.

repackage

Repackages the packaged JAR archive with optional metadata and GAR extension.

11.2 Creating a Coherence Project from a Maven Archetype

You can create a new Coherence project using the Coherence Maven archetype.

  1. To create a new Coherence project using the Coherence Maven archetype, issue a command similar to the following:
    mvn archetype:generate
        -DarchetypeGroupId=com.oracle.coherence.archetype
        -DarchetypeArtifactId=gar-maven-archetype
        -DarchetypeVersion=12.2.1-0-0
        -DgroupId=org.mycompany
        -DartifactId=my-gar-project
        -Dversion=1.0-SNAPSHOT
    

    This command runs Maven's archetype:generate goal which lets you create a new project from an archetype. Table 11-3 describes the parameters.

    Table 11-3 Parameters for the Coherence Projects

    Parameter Purpose

    archetypeGroupId

    The group ID of the archetype that you want to use to create the new project. This must be com.oracle.coherence.archetype.

    archetypeArtifactId

    The artifact ID of the archetype that you want to use to create the new project. This must be gar-maven-archetype.

    archetypeVersion

    The version of the archetype that you want to use to create the new project. This must be 12.2.1-0-0.

    groupId

    The group ID for your new project. This usually starts with your organization's domain name in reverse format.

    artifactId

    The artifact ID for your new project. This is usually an identifier for this project.

    version

    The version for your new project. This is usually 1.0-SNAPSHOT for a new project.

    You can also run the command without any arguments, as shown in the following example. In this case, Maven displays a list of available archetypes and prompts you to enter the required information.

    mvn archetype:generate
    

    After creating your project, it contains the following files:

    Table 11-4 describes the files included in the project.

    Table 11-4 Files Created for the Coherence Project

    File Purpose

    pom.xml

    The Maven Project Object Model (POM) file that describes your new project. It includes the Maven coordinates that you specified for your project and the appropriate plug-in definitions to use the Coherence Maven plug-in to build your project into a gar file.

    cache-config.xml

    A starter Coherence cache configuration file.

    coherence-application.xml

    A starter Coherence GAR deployment descriptor for your GAR file.

    pof-config.xml

    A starter Coherence Portable Object Format (POF) configuration file. The POF configuration file is processed and inserted into the final GAR file if the plug-in option generatePof is set to true. By default, POF configuration metadata will not be generated.

  2. If you are using POF in your project, you must add the following parameter into your project's POM file:
    Parameter Purpose

    generatePof

    The POF configuration file is generated and inserted into the final GAR file if this plug-in option is true. The configuration file is generated by scanning all classes in the GAR's classpath annotated with the class com.tangosol.io.pof.annotation.Portable. By default, POF configuration metadata is not generated.

  3. To generate a GAR with correctly generated pof-config.xml, add the following to your GAR plug-in configuration in the POM:
    <build>
    <plugins>
    …
        <plugin>
          <groupId>com.oracle.coherence</groupId>
          <artifactId>gar-maven-plugin</artifactId>
          <version>12.2.1-0-0</version>
          <extensions>true</extensions>
          <configuration>
             <generatePof>true</generatePof>
          </configuration>
        </plugin>
    …
      </plugins>
    </build>
    

11.3 Building Your Coherence Project with Maven

After you have written your project code, you can use Maven to build the project:

  1. To compile the source code in your project, execute the following command:
    mvn compile
    
  2. To package the compiled source into a GAR, execute the following command. Note that this command runs all steps up to package, including the compile.
    mvn package
    

11.4 Deploying Your Coherence Project to the WebLogic Server Coherence Container with Maven

To deploy your GAR to a Coherence Container in a WebLogic Server environment, you must add some additional configuration to your project's POM file.

Take these steps:

  1. Add instructions to use the Oracle WebLogic Maven plug-in to deploy the GAR, as shown in the following example:
              <plugin>
                <groupId>com.oracle.weblogic</groupId>
                <artifactId>weblogic-maven-plugin</artifactId>
                <version>12.2.1-0-0</version>
                <executions>
                  <!--Deploy the application to the server-->
                  <execution>
                    <phase>pre-integration-test</phase>
                    <goals>
                      <goal>deploy</goal>
                    </goals>
                    <configuration>
                      <adminurl>t3://localhost:7001</adminurl>
                      <user>weblogic</user>
                      <password>welcome1</password>
                      <!--The location of the file or directory to be deployed-->
                      <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
                      <!--The target servers where the application is deployed-->
                      <targets>AdminServer</targets>
                      <verbose>true</verbose>
                      <name>${project.build.finalName}</name>
                    </configuration>
                  </execution>
                </executions>
              </plugin>
    
  2. After you have added this section to your POM, use the following command to compile, package, and deploy your GAR to the WebLogic Server:
    mvn verify
    

11.5 Building a More Complete Coherence Example

In a real application, you are likely to have not just a GAR project, but also some kind of client project that interacts with the Coherence cache established by the GAR.

Refer to Building a Real Application with Maven to see an example that includes a Coherence GAR and a web application (WAR) that interacts with it.