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

11.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 11-1 describes the Maven coordinates.

Table 11-1 Maven Coordinates with Coherence

artifacts groupId artifactId version

Coherence plug-in




Coherence archetype




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

Table 11-2 Oracle Coherence Goals

Goal Purpose


Generates the project's POF configuration file.


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


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

11.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

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


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


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


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


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


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


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 11-4.

Table 11-4 Files Created for the Coherence Project

File Purpose


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.


A starter Coherence cache configuration file.


A starter Coherence GAR deployment descriptor for your GAR file.


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:


11.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

11.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:

              <!--Deploy the application to the server-->
                  <!--The location of the file or directory to be deployed-->
                  <!--The target servers where the application is deployed-->

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