Fusion Middleware Documentation
Advanced Search


Developing Applications Using Continuous Integration
Close Window

Table of Contents

Show All | Collapse

10 Building Oracle Coherence Projects with Maven

This chapter provides details on how to use the Oracle Coherence archetypes to create, build, and deploy Oracle Coherence applications.

This chapter includes the following topics:

10.1 Introduction to Building Oracle Coherence Projects with Maven

A Maven plug-in and an archetype is provided for Oracle Coherence Grid Archive (GAR) projects. Table 10-1 describes the Maven coordinates.

Table 10-1 Maven Coordinates with Coherence

artifacts groupId artifactId version

Coherence plug-in

com.oracle.coherence

maven-gar-plugin

12.1.3-0-0

Coherence archetype

com.oracle.coherence

maven-gar-archetype

12.1.3-0-0


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

Table 10-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.


10.2 Creating a Project from a Maven Archetype

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
    -DarchetypeArtifactId=maven-gar-archetype
    -DarchetypeVersion=12.1.3-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 10-3 describes the parameters.

Table 10-3 Parameters for the Coherence Projects

Parameter Purpose

archetypeGroupId

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

archetypeArtifactId

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

archetypeVersion

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

groupId

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

artifactId

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

version

Identifies 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:

Description of maven_dt_006.png follows
Description of the illustration maven_dt_006.png

There are a number of files included in the project, as described in Table 10-4.

Table 10-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.


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.


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>maven-gar-plugin</artifactId>
      <version>12.1.3-0-0</version>
      <extensions>true</extensions>
      <configuration>
         <generatePof>true</generatePof>
      </configuration>
    </plugin>
…
  </plugins>
</build>

10.3 Building Your Project with Maven

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

To compile the source code in your project, execute the following command:

mvn compile

To package the compiled source into a GAR, execute the following command. Note that this runs all steps up to package, including the compile.

mvn package

10.4 Deploying Your 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. This is done by adding 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.1.3-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>

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

10.5 Building a More Complete 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 Chapter 14, "Building a Real Application with Maven" to see an example that includes a Coherence GAR and a web application (WAR) that interacts with it.