Fusion Middleware Documentation
Advanced Search


Developing Applications Using Continuous Integration
Close Window

Table of Contents

Show All | Collapse

11 Building a Real Application with Maven

Many real world applications include modules that are targeted to be deployed on different runtime environments. For example, you may have a web application that uses data stored in a Coherence cache. This chapter describes how to build such a web application.

This chapter contains the following sections:

11.1 Introducing the Example

The example application that you build in this chapter displays a list of people, with their names and age, on a web page. It also allows you to add a new person. The details of the people are stored in a Coherence cache. This application contains the following parts:

  • A Coherence GAR project, which contains a Person POJO which you need to build into a Portable Object, a utility class to access the cache, and Coherence cache definitions.

  • A Java EE web application, which you need to build into a WAR, which contains a servlet and a deployment descriptor.

  • A project to assemble the GAR and WAR into an EAR and deploy that EAR to WebLogic Server.

In this example, you can see how to build a multi-module Maven project, with dependencies between modules, and how to assemble our application components into a deployable EAR file that contains the whole application.

The aim of this chapter is to show how to use Maven to build whole applications, not to demonstrate how to write web or Coherence applications, so the content of the example itself, in terms of the servlet and the coherence code, is quite basic. For more information, refer to Chapter 9 and Chapter 10.

11.2 Multi-Module Maven Projects

Maven lets you to create projects with multiple modules. Each module is in effect another Maven project. At the highest level, you have a POM file that tells Maven about the modules and lets you to build the whole application with one Maven command.

Each of the modules are placed in a subdirectory of the root of the top-level project. In the example, the top-level project is called my-real-app and the three modules are my-real-app-gar, my-real-app-war and my-real-app-ear. The Maven coordinates of the projects are as follows:

GroupId ArtifactId Version Packaging

org.mycompany

my-real-app

1.0-SNAPSHOT

pom

org.mycompany

my-real-app-gar

1.0-SNAPSHOT

gar

org.mycompany

my-real-app-war

1.0-SNAPSHOT

war

org.mycompany

my-real-app-ear

1.0-SNAPSHOT

ear


The following are the files that make up the application:

pom.xml


my-real-app-gar/pom.xml
my-real-app-gar/src/main/resources/META-INF/pof-config.xml
my-real-app-gar/src/main/resources/META-INF/coherence-application.xml
my-real-app-gar/src/main/resources/META-INF/cache-config.xml
my-real-app-gar/src/main/java/org/mycompany/CacheWrapper.java
my-real-app-gar/src/main/java/org/mycompany/Person.java


my-real-app-war/pom.xml
my-real-app-war/src/main/webapp/WEB-INF/web.xml
my-real-app-war/src/main/java/org/mycompany/servlets/MyServlet.java


my-real-app-ear/pom.xml
my-real-app-ear/src/main/application/META-INF/weblogic-application.xml

At the highest level, the POM file points to the three modules.

The my-real-app-gar directory contains the Coherence GAR project. It contains its own POM, the Coherence configuration files, a POJO/POF class definition (Person.java) and a utility class that is needed to access the cache (CacheWrapper.java).

The my-real-app-war directory contains the web application. It contains its own POM, a Servlet and a deployment descriptor. This project depends on the my-real-app-gar project.

The my-real-app-ear directory contains the deployment descriptor for the EAR file and a POM file to build and deploy the EAR.

11.3 Getting Started Building a Maven Project

Create a directory to hold the projects, using the following command:

mkdir my-real-app

Throughout the rest of this chapter, paths relative to this directory are given.

11.4 Creating the GAR Project

You can create the GAR project either using an archetype as described in Section 10.2, or you can create the directories and files manually.

To use the archetype, run the following command:

mvn archetype:generate
    -DarchetypeGroupId=com.oracle.coherence
    -DarchetypeArtifactId=maven-gar-archetype
    -DarchetypeVersion=12.1.2-0-0
    -DgroupId=org.mycompany
    -DartifactId=my-real-app-gar
    -Dversion=1.0-SNAPSHOT

To create the project manually, use the following commands to create the necessary directories:

mkdir -p my-real-app-gar/src/main/resources/META-INF
mkdir -p my-real-app-gar/src/main/java/org/mycompany

This section includes the following topics:

11.4.1 The POM File

If you use the archetype, you will already have a POM file. You should modify that file to match the following example. If you create the project manually, you should create the POM file (my-real-app-gar/pom.xml) with the following contents:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.mycompany</groupId>
  <artifactId>my-real-app-gar</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>gar</packaging>
  <parent>
    <groupId>org.mycompany</groupId>
    <artifactId>my-real-app</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <dependencies>
    <dependency>
      <groupId>com.oracle.coherence</groupId>
      <artifactId>coherence</artifactId>
      <version>12.1.2-0-0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>com.oracle.coherence</groupId>
          <artifactId>maven-gar-plugin</artifactId>
          <version>${coherence.version}</version>
          <extensions>true</extensions>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>com.oracle.coherence</groupId>
        <artifactId>maven-gar-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
            <generatePof>true</generatePof>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Examine the POM file to understand what each part stands for. The Maven coordinates for this project are set:

<groupId>org.mycompany</groupId>
  <artifactId>my-real-app-gar</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>gar</packaging>

Notice that the packaging is gar because we are going to use the Coherence Maven plug-in to build this project into a Coherence GAR file.

The coordinates of the parent project are set. These coordinates point back to the top-level project. You need to create the POM for the top-level project in a later step.

<parent>
    <groupId>org.mycompany</groupId>
    <artifactId>my-real-app</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>

The dependencies section identifies any dependencies that this project has. In this case, you depend only on the Coherence library, that is, com.oracle.coherence:coherence:12.1.2-0-0. The scope provided means that this library is just for compilation and does not need to be packaged in the artifact that you build (the GAR file) as it is already provided in the runtime environment.

<dependencies>
    <dependency>
      <groupId>com.oracle.coherence</groupId>
      <artifactId>coherence</artifactId>
      <version>12.1.2-0-0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

The pluginManagement section tells Maven to enable extensions for this plug-in. This is necessary to allow Maven to recognize GAR files as a target artefact type.

<pluginManagement>
      <plugins>
        <plugin>
          <groupId>com.oracle.coherence</groupId>
          <artifactId>maven-gar-plugin</artifactId>
          <version>${coherence.version}</version>
          <extensions>true</extensions>
        </plugin>
      </plugins>
    </pluginManagement>

The plug-ins section includes any information that you must pass to the Coherence GAR plug-in. In this case, you must set generatePof to true so that the plug-in looks for POJOs with POF annotations and generate the necessary artifacts.

<plugins>
      <plugin>
        <groupId>com.oracle.coherence</groupId>
        <artifactId>maven-gar-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
            <generatePof>true</generatePof>
        </configuration>
      </plugin>
    </plugins>

11.4.2 Creating or Modifying the Coherence Configuration Files

There are three Coherence configuration files that you need in your GAR project. If you use the archetype, the files already exist, but you need to modify them to match the following examples. If you create the project manually, you should create these files in the locations indicated:

my-real-app-gar/src/main/resources/META-INF/pof-config.xml
my-real-app-gar/src/main/resources/META-INF/coherence-application.xml
my-real-app-gar/src/main/resources/META-INF/cache-config.xml

The following are the contents for the pof-config.xml file:

<?xml version="1.0"?>
<pof-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="http://xmlns.oracle.com/coherence/coherence-pof-config"
            xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-pof  -config coherence-pof-config.xsd">
<user-type-list>
  <!-- by default just include coherence POF user types -->
  <include>coherence-pof-config.xml</include>   
</user-type-list>
</pof-config>

The following are the contents for the coherence-application.xml file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<coherence-application xmlns="http://xmlns.oracle.com/weblogic/coherence-application">
  <cache-configuration-ref>META-INF/cache-config.xml</cache-configuration-ref>
  <pof-configuration-ref>META-INF/pof-config.xml</pof-configuration-ref>
</coherence-application>

Both of these files require little or no modification if you created them with the archetype.

The cache-config.xml file must be updated if you have used the archetype:

In this file, create a cache named People, with a caching scheme named real-distributed-gar and a service name of RealDistributedCache, which uses the local backing scheme and is automatically started. If you are not familiar with these terms, see Chapter 10.

<?xml version="1.0"?>
<cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
              xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">
<caching-scheme-mapping>
    <cache-mapping>
      <cache-name>People</cache-name>
      <scheme-name>real-distributed-gar</scheme-name>
    </cache-mapping>
  </caching-scheme-mapping>
<caching-schemes>
    <distributed-scheme>
      <scheme-name>real-distributed-gar</scheme-name>
      <service-name>RealDistributedCache</service-name>
      <backing-map-scheme>
        <local-scheme/>
      </backing-map-scheme>
      <autostart>true</autostart>
    </distributed-scheme>
  </caching-schemes>
</cache-config>

11.4.3 Creating the Portable Objects

Create the Person object, which will store information in the cache. Create a new Java class in the following location:

my-real-app-gar/src/main/java/org/mycompany/Person.java

The following is the content for this class:

package org.mycompany;
import com.tangosol.io.pof.annotation.Portable;
import com.tangosol.io.pof.annotation.PortableProperty;
@Portable
public class Person {
  @PortableProperty(0)
  public String name;
  @PortableProperty(1)
  public int age;
 
  public Person() {}
public Person(String name, int age) {
    this.name = name;
    this.age = age;
  }
public String getName() { return this.name; }
  public int    getAge()  { return this.age;  }
}

This POJO tells Coherence what to do with the class. The focus of this chapter is on building applications with Maven, it does not go into the details of writing Coherence applications. For more information on Coherence, refer to Chapter 10.

11.4.4 Creating a Wrapper Class to Access the Cache

Create a small wrapper class that you can use to access the cache. Create another Java class in this location:

my-real-app-gar/src/main/java/org/mycompany/CacheWrapper.java

The following is the content for this class:

package org.mycompany;
import org.mycompany.Person;
import com.tangosol.net.CacheFactory;
import java.util.Set;
public class CacheWrapper {
  private static CacheWrapper INSTANCE;
public Set getPeople() {
    return CacheFactory.getCache("People").entrySet();
  }
public void addPerson(int personid, String name, int age) {
    CacheFactory.getCache("People").put(personid, new Person(name, age));
  }
public static final CacheWrapper getInstance() {
    if(INSTANCE == null) INSTANCE = new CacheWrapper();
    return INSTANCE;
  }
}

Later, you can use this class in a Servlet to get data from the cache and to add new data to the cache.

11.5 Creating the WAR project

You can create the WAR project either using an archetype as described in Chapter 9, or you can create the directories and files manually.

To use the archetype, run the following command:

mvn archetype:generate
    -DarchetypeArtifactId=basic-webapp
    -DarchetypeVersion=12.1.2-0-0
    -DgroupId=org.mycompany
    -DartifactId=my-real-app-war
    -Dversion=1.0-SNAPSHOT

If you use the archetype, you must remove any unnecessary files included in the project.

To create the project manually, use the following commands to create the necessary directories:

mkdir -p my-real-app-war/src/main/webapp/WEB-INF
mkdir -p my-real-app-war/src/main/java/org/mycompany/servlets

This section includes the following topics:

11.5.1 Creating or Modifying the POM File

If you use the archetype, the POM file already exists. You should modify that file to match the following example. If you created the project manually, you should create the POM file (my-real-app-war/pom.xml) with the following contents:

<project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.mycompany</groupId>
   <artifactId>my-real-app-war</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>war</packaging>
   <parent>
      <groupId>org.mycompany</groupId>
      <artifactId>my-real-app</artifactId>
      <version>1.0-SNAPSHOT</version>
   </parent>
   <name>my-real-app-war</name>
   <dependencies>
       <dependency>
           <groupId>org.mycompany</groupId>
           <artifactId>my-real-app-gar</artifactId>
           <version>1.0-SNAPSHOT</version>
           <scope>provided</scope>
       </dependency>
       <dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>javax.servlet-api</artifactId>
           <version>3.0.1</version>
           <scope>provided</scope>
       </dependency>
   </dependencies>
</project>

Let's review what is included in the POM file. First, you must set the coordinates for this project. Notice that the packaging for this project is war.

<groupId>org.mycompany</groupId>
   <artifactId>my-real-app-war</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>war</packaging>

Then, define the parent, as you did in the GAR project:

<parent>
      <groupId>org.mycompany</groupId>
      <artifactId>my-real-app</artifactId>
      <version>1.0-SNAPSHOT</version>
   </parent>

Finally, list the dependencies for this project. In this case, there are two dependencies: the GAR project to access the POJO and utility classes you defined there and the Servlet API. This sets the display-name for the web application.

<dependencies>
       <dependency>
           <groupId>org.mycompany</groupId>
           <artifactId>my-real-app-gar</artifactId>
           <version>1.0-SNAPSHOT</version>
           <scope>provided</scope>
       </dependency>
       <dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>javax.servlet-api</artifactId>
           <version>3.0.1</version>
           <scope>provided</scope>
       </dependency>
   </dependencies>

11.5.2 Creating the Deployment Descriptor

The web application has a simple Java EE deployment descriptor, located at this location:

my-real-app-war/src/main/webapp/WEB-INF/web.xml

The following are the contents of this file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

   <display-name>my-real-app-war</display-name>

</web-app>

This sets the display-name for the web application.

11.5.3 Creating the Servlet

To create the servlet, locate the MyServlet.java file:

my-real-app-war/src/main/java/org/mycompany/servlets/MyServlet.java

The servlet displays a list of people that are currently in the cache and allows you to add a new person to the cache. The aim of the section is to learn how to build these types of applications with Maven, not to learn how to write Java EE web applications, hence the use of a simplistic servlet.

The following is the content for the servlet class:

package org.mycompany.servlets;
import org.mycompany.Person;
import org.mycompany.CacheWrapper;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Set;
import java.util.Iterator;
@WebServlet(name = "MyServlet", urlPatterns = "MyServlet")
public class MyServlet extends HttpServlet {
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    String id = request.getParameter("id");
    String name = request.getParameter("name");
    String age = request.getParameter("age");
    if (name == null || name.isEmpty()
        || age == null || age.isEmpty()
        || id == null || id.isEmpty()) {
      // no need to add a new entry
    } else {
      // we have a new entry - so add it
      CacheWrapper.getInstance().addPerson(Integer.parseInt(id), name, Integer.parseInt(age));
    }
    renderPage(request, response);
  }
protected void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    renderPage(request, response);
  }
private void renderPage(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    // get the data
    Set people = CacheWrapper.getInstance().getPeople();
    PrintWriter out = response.getWriter();
    out.write("<html><head><title>MyServlet</title></head><body>");
    out.write("<h2>Add a new person</h2>");
    out.write("<form name=\"myform\" method=\"POST\">");
    out.write("ID:<input type=\"text\" name=\"id\"/><br/>");
    out.write("Name:<input type=\"text\" name=\"name\"/><br/>");
    out.write("Age:<input type=\"text\" name=\"age\"/><br/>");
    out.write("<input type=\"submit\" name=\"submit\" value=\"add\"/>");
    out.write("</form>");
    out.write("<h2>People in the cache now</h2>");
    out.write("<table><tr><th>ID</th><th>Name</th><th>Age</th></tr>");
    // for each person in data
    if (people != null) {
      Iterator i = people.iterator();
      while (i.hasNext()) {
        Map.Entry entry = (Map.Entry)i.next();
        out.write("<tr><td>"
          + entry.getKey()
          + "</td><td>"
          + ((Person)entry.getValue()).getName()
          + "</td><td>"
          + ((Person)entry.getValue()).getAge()
          + "</td></tr>");
      }
    }
    out.write("</table></body></html>");
  }
}

Check if the user has entered any data in the form. If so, add a new person to the cache using that data. Note that this application has fairly minimal error handling. To add the new person to the cache, use the addPerson() method in the CacheWrapper class that you created in your GAR project.

Print out the contents of the cache in a table. In this example, assume that the cache has a reasonably small number of entries, and read them all using the getPeople() method in the CacheWrapper class.

11.6 Creating the EAR project

The EAR project manages assembling the WAR and the GAR into an EAR. Create this project manually using the following command:

mkdir -p my-real-app-ear/src/main/application/META-INF

There are two files in this project: a POM file and a deployment descriptor:

my-real-app-ear/pom.xml

my-real-app-ear/src/main/application/META-INF/weblogic-application.xml

This section includes the following topics:

11.6.1 The POM File

The following are the contents of the POM file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.mycompany</groupId>
   <artifactId>my-real-app-ear</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>ear</packaging>
   <parent>
      <groupId>org.mycompany</groupId>
      <artifactId>my-real-app</artifactId>
      <version>1.0-SNAPSHOT</version>
   </parent>
   <name>ear assembly</name>
   <dependencies>
      <dependency>
        <groupId>org.mycompany</groupId>
        <artifactId>my-real-app-gar</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>gar</type>
        <scope>optional</scope>
      </dependency>
      <dependency>
         <groupId>org.mycompany</groupId>
         <artifactId>my-real-app-war</artifactId>
         <version>1.0-SNAPSHOT</version>
         <type>war</type>
      </dependency>
   </dependencies>
   <build>
      <plugins>
         <plugin>
            <artifactId>maven-ear-plugin</artifactId>
            <configuration>
               <archive>
                  <manifest>
                     <addClasspath>true</addClasspath>
                  </manifest>
               </archive>
               <artifactTypeMappings>
                  <artifactTypeMapping type="gar" mapping="jar"/>
               </artifactTypeMappings>
            </configuration>
         </plugin>
         <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-dependency-plugin</artifactId>
             <executions>
                <execution>
                    <id>copy-gar-locally</id>
                    <phase>prepare-package</phase>
                    <goals>
                       <goal>copy</goal>
                    </goals>
                    <configuration>
                       <artifactItems>
                           <artifactItem>
                              <groupId>org.mycompany</groupId>
                              <artifactId>my-real-app-gar</artifactId>
                              <version>1.0-SNAPSHOT</version>
                              <type>gar</type>
                          </artifactItem>
                      </artifactItems>
                    </configuration>
                  </execution>
               </executions>
          </plugin>
        <plugin>
          <groupId>com.oracle.weblogic</groupId>
          <artifactId>weblogic-maven-plugin</artifactId>
          <version>12.1.2-0-0</version>
          <executions>
            <!--Deploy the application to the server-->
            <execution>
              <phase>pre-integration-test</phase>
              <goals>
                <goal>deploy</goal>
              </goals>
              <configuration>
                <adminurl>t3://127.0.0.1:7001</adminurl>
                <user>weblogic</user>
                <password>welcome1</password>
                <middlewareHome>/home/mark/space/maven/wls030213</middlewareHome>
                <!--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>
      </plugins>
   </build>
</project>

Set the Maven coordinates for this project, and point to the parent:

<groupId>org.mycompany</groupId>
   <artifactId>my-real-app-ear</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>ear</packaging>
   <parent>
      <groupId>org.mycompany</groupId>
      <artifactId>my-real-app</artifactId>
      <version>1.0-SNAPSHOT</version>
   </parent>

Next, there are the dependencies on the WAR and GAR projects:

<dependencies>
      <dependency>
        <groupId>org.mycompany</groupId>
        <artifactId>my-real-app-gar</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>gar</type>
        <scope>optional</scope>
      </dependency>
      <dependency>
         <groupId>org.mycompany</groupId>
         <artifactId>my-real-app-war</artifactId>
         <version>1.0-SNAPSHOT</version>
         <type>war</type>
      </dependency>
   </dependencies>

There are three separate plug-in configurations. The first of these is for the maven-ear-plugin. You need to tell it to treat a gar file like a jar file by adding an artifactTypeMapping as in the following example:

<plugin>
            <artifactId>maven-ear-plugin</artifactId>
            <configuration>
               <archive>
                  <manifest>
                     <addClasspath>true</addClasspath>
                  </manifest>
               </archive>
               <artifactTypeMappings>
                  <artifactTypeMapping type="gar" mapping="jar"/>
               </artifactTypeMappings>
            </configuration>
        </plugin>

Configure the maven-dependency-plugin to copy the GAR file from the my-real-app-gar project's output (target) directory into the EAR project:

<plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-dependency-plugin</artifactId>
             <executions>
                <execution>
                    <id>copy-gar-locally</id>
                    <phase>prepare-package</phase>
                    <goals>
                       <goal>copy</goal>
                    </goals>
                    <configuration>
                       <artifactItems>
                           <artifactItem>
                              <groupId>org.mycompany</groupId>
                              <artifactId>my-real-app-gar</artifactId>
                              <version>1.0-SNAPSHOT</version>
                              <type>gar</type>
                          </artifactItem>
                      </artifactItems>
                    </configuration>
                  </execution>
               </executions>
           </plugin>

And finally, tells the weblogic-maven-plugin how to deploy the resulting EAR file. In this section, you must update the adminurl, user, password, and target parameters to match your environment. For details on these parameters, see Table 9-1.

<plugin>
          <groupId>com.oracle.weblogic</groupId>
          <artifactId>weblogic-maven-plugin</artifactId>
          <version>12.1.2-0-0</version>
          <executions>
            <!--Deploy the application to the server-->
            <execution>
              <phase>pre-integration-test</phase>
              <goals>
                <goal>deploy</goal>
              </goals>
              <configuration>
                <adminurl>t3://127.0.0.1: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>

Once you have completed the POM project, add a deployment descriptor.

11.6.2 Deployment Descriptor

The WebLogic deployment descriptor for the EAR file is located in this file:

my-real-app-ear/src/main/application/META-INF/weblogic-application.xml

The following are the contents:

<weblogic-application>
       <module>
             <name>GAR</name>
             <type>GAR</type>
             <path>my-real-app-gar-1.0-SNAPSHOT.gar</path>
       </module>
</weblogic-application>

This deployment descriptor provides the details for where in the EAR file the GAR file should be placed, and what it should be called.

11.7 Creating the Top-Level POM

Create the top-level POM. This is located in the pom.xml file in the root directory of your application and contains the following:

<project>
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.mycompany</groupId>
   <artifactId>my-real-app</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>pom</packaging>
   <name>my-real-app</name>
   <modules>
      <module>my-real-app-war</module>
      <module>my-real-app-gar</module>
      <module>my-real-app-ear</module>
   </modules>
   <properties>
       <coherence.version>12.1.2-0-0</coherence.version>
   </properties>
</project>

Set the coordinates for the project. You will notice that these match the parent coordinates you specified in each of the three projects. Note that the packaging is pom. This tells Maven that this project is an assembly of a set of sub-projects, as named in the modules section.

There are one module entry for each of the three sub-projects.

Since this POM is the parent of the other three, and since POM's inherit from their parents, you can add any common properties to this POM and it will be available in all the three sub-projects. In this case, you are adding the property coherence.version.

11.8 Building the Application Using Maven

You can now build the application using Maven by using one or more of the following commands (in the top-level directory my-real-app):

mvn compile
mvn package
mvn verify

Maven executes all of the phases up to the one named. These commands have the following effect:

Command Details

mvn compile

Compile the Java source into target class files.

mvn package

  1. Compile the Java source into target class files.

  2. Create the archive (WAR, GAR, and so on) containing compiled files and resources (deployment descriptors, configuration files, and so on).

mvn verify

  1. Compile the Java source into target Class files.

  2. Create the archive (WAR, GAR, and so on) containing compiled files and resources (deployment descriptors, configuration files, and so on).

  3. Deploy the EAR file to the WebLogic Server environment.