Maven integration for portlet projects with IBM Rational Application Developer

Part 2. EAR deployment

Comments

Content series:

This content is part # of # in the series: Maven integration for portlet projects with IBM Rational Application Developer

Stay tuned for additional content in this series.

This content is part of the series:Maven integration for portlet projects with IBM Rational Application Developer

Stay tuned for additional content in this series.

How a portlet project is created using IBM portlet archetype and deployed to the IBM® WebSphere® Portal Server using the IBM portal-maven-deployment plugin was the topic of Maven integration for portlet projects with IBM Rational Application Developer, published on developerWorks September 24, 2013. The article explained portlet (as a WAR) deployment using the IBM portal-maven-deployment plugin. This article, explains portlet deployment, as an EAR, using IBM portal-maven-deployment plugin. This article is a continuation of the article published in 2013.

In Maven, projects are referred to as modules. Each module has a configuration file named pom.xml. An Enterprise application project usually contains references to other J2EE modules and Java projects that are combined to compose an EAR file. To deploy the portlet as an EAR you need to:

  • Create an EAR module.
  • Create WAR modules (i.e. portlets).
  • Add references of those WAR modules into your EAR module.

To achieve this through Maven there are two options. The first option is a single module project approach. In the single module project approach each module is built separately and in a specific order to resolve the dependencies.

The second approach is a multi-module project. With the multi-module project approach, all modules (parent and other referenced modules) are built together using project aggregation. The multi-module project with Eclipse or an Eclipse-based IDE (Integrated Development Environment) can be of a hierarchical directory project layout or a flat directory Eclipse-like layout. This article is based on the flat directory multi-module project approach. Figure 1 illustrates the structure of a flat directory multi-module project.

Figure 1. Flat directory multi-module project structure
Directory structure of multi-module project
Directory structure of multi-module project

To deploy a portlet as an EAR complete these steps:

  • Create a parent POM module.
  • Create a portlet project using the IBM archetype.
  • Create an EAR project.
  • Convert the EAR project to Maven project.
  • Bind the parent POM, Portlet module and the EAR module.
  • Configure the IBM deployment plugin in EAR POM.
  • Publish the EAR project to IBM WebSphere Portal Server.

Create a parent POM module

In a multi-module project, the parent module is defined by a POM, referenced as parent POM, which can refer to one or more sub modules. The parent POM provides project aggregation by creating bindings between other Maven modules. Use the parent POM to define settings or configuration parameters to make these parameters available to all sub modules. To create a parent POM follow these steps:

  1. File > New > Project....
  2. Select General > Project.
  3. In the New Project dialog box, click Next.
  4. Name the Project root.
  5. Click the Finish button.

A project is created in the workspace. Figure 2 shows the root project in the IBM® Rational® Application Developer for WebSphere Software workspace.

Figure 2. The root project in the Rational Application Developer workspace
Root folder in the workspace
Root folder in the workspace
  1. Select the created project.
  2. In the context menu click Configure > Convert to Maven Project.
  3. The "Create new POM" dialog window opens.
  4. Choose com.test.demo for Group Id.
  5. Select the packaging type pom.
  6. Click the Finish button.

Figure 3 shows Create new POM wizard and the data used to create the new POM.

Figure 3. Creating the parent POM
Create a new POM dialog
Create a new POM dialog
  1. pom.xml (i.e. parent POM) is created in the root project.

Create a portlet project using IBM archetype

The IBM archetype (portletapp-portlet20) for portlet projects is available on the IBM public repository for Maven. You can use this IBM archetype to create a JSR 286 portlet project targeting WebSphere Portal Server v8.0.

To create a portlet project using the IBM archetype:

  1. File > New > Project.....
  2. Select Maven > Maven Project.
  3. Click Next on the New Project dialog.
  4. The New Maven Project Wizard opens.
  5. Accept the default values on the first page of the wizard.
  6. Click the Next button.
  7. On the Select an Archetype page, select All Catalogs in the Catalog drop-down.
  8. Type portlet20 in the Filter text field.
  9. The archetype table should list:
    • Group Id: com.ibm.tools.archetype
    • Artifact Id: portletapp-portlet20
    • Version 1.0.1
  10. Select the IBM archetype portletapp-portlet20.
  11. Click the Next button.

The New Maven Project dialog shown in Figure 4 opens.

Figure 4. Create a portlet project using IBM archetype
New Maven Project wizard
New Maven Project wizard
  1. Type these values:
    • Group Id: com.test.demo.root
    • Artifact Id: MVNPortlet
    • portlettitle : MVNPortlet
    • portletclass: MVNPortlet
  2. Click the Finish button.

The portlet project is created.

Create an EAR project

An enterprise application project contains the hierarchy of resources required to deploy a J2EE enterprise application (often referred to as an EAR file). It can contain a set of references to other J2EE modules and Java projects that are combined to compose an EAR file.

Complete these steps to create the EAR project:

  1. File > New > Project....
  2. Select Java EE > Enterprise Application Project.
  3. Click the Next button.
  4. In the Project Name field type MVNPortletEAR.
  5. Select target runtime as <None>.
  6. Click the Finish button.

Convert the EAR project to a Maven project

Figure 5 shows the Create new POM page. Follow these steps to create a POM for an EAR module:

  1. Select the created EAR project.
  2. In context menu, click Configure > Convert to Maven Project.
  3. The Create new POM dialog page opens.
  4. Select the Group Id com.test.demo.root.
  5. Click the Finish button.
Figure 5. Create a POM for an EAR module
Dialog to create a new POM for EAR module
Dialog to create a new POM for EAR module

An enterprise application project is created in the workspace. Figure 6 shows the tree structure of this multi-module project.

Figure 6. Project tree structure
Project structure for different modules in workspace
Project structure for different modules in workspace

Binding the parent POM, Portlet module and EAR module

To configure a multi-module project you need to properly bind the parent POM with its constituent modules.

Adding modules to the parent POM

  1. Open the pom.xml of the parent POM module.
  2. Select the Overview tab if it is not already selected.
  3. In the Modules section, click the Add button to add the EAR and WAR modules.
  4. Save the pom.xml.
  5. Update the project by clicking Maven > Update Project... in the project's context menu.

Figure 7 shows the dialog page to add sub modules in the parent POM.

Figure 7. Adding sub modules in parent POM
Adding reference of sub modules to Parent POM
Adding reference of sub modules to Parent POM

Add a parent POM reference to the sub module's POM

  1. Open the pom.xml file of the WAR (Portlet) module.
  2. Select the Overview tab if it is not selected by default.
  3. In the Parent section of the page, click the Select Parent icon.
  4. Search for the parent by their Group Id com.test.demo, or the Artifact Id root.
  5. The root module displays in the search result select the root module.
  6. Click OK.
  7. Set the relative path of the parent module ../root/pom.xml.
  8. Save the changes.
  9. Update the project with in the project's context menu by following the path Maven > Update Project....

Repeat the steps to add the parent POM reference for the EAR module.

Figure 8 is a reference for how to add the parent POM in sub modules.

Figure 8. Adding reference of parent POM in sub modules
Adding parent POM's reference to WAR module
Adding parent POM's reference to WAR module

Configure the Maven-Ear-plugin in an EAR POM

  1. Open pom.xml of the EAR module.
  2. Click on the Dependencies tab.
  3. In the dependencies section add the WAR module using their group id or artifact ids.
  4. Click on the pom.xml tab.
  5. In the Maven-EAR-plugin configuration section, set the value of the configuration parameter generateApplicationXml to true.

Listing 1 is the maven-ear-plugin configuration.

Listing 1. Maven-ear-plugin configuration in EAR POM
<plugin> 
    <artifactId>maven-ear-plugin</artifactId>
    <version>2.8</version>
    <configuration>
        <version>6</version>
        <generateApplicationXml>true</generateApplicationXml>
    </configuration>
</plugin>

Listing 2 shows how to add the deployment plugin. The <plugins> tag publishes the EAR project. This is the same code to use for a WAR deployment.

Listing 2. Update deployment plugin with configuration parameters
<plugin> 
    <groupId>com.ibm.tools.plugin</groupId>
    <artifactId>portal-deployment-maven-plugin</artifactId>
    <version>1.0</version>
    <executions>
        <execution>
            <phase>integration-test</phase>
            <configuration>
                <username>wpsadmin</username>
                <password>wpsadmin</password>
                <hostname>localhost</hostname>
                <port>10039</port>
                <profilepath>C:\IBM\WP80\wp_profile</profilepath>
                <cell>awan</cell>
            </configuration>
                <goals>
                    <goal>deploy-portlet</goal>
                </goals>
        </execution>
    </executions>
</plugin>
  1. Save the changes.
  2. Update the project by following the path Maven > Update Project... in the project context menu.

Make sure there are no errors in when you look at the Problems view or the Markers view.

Publish an EAR project using the Maven plugin

To publish the portlet project to IBM WebSphere Portal Server as an EAR project:

  1. Select the root module.
  2. From the context menu, select Run As > Maven Build....
  3. In the Goal field on the configuration dialog page, type integration-test.
  4. Click the Run button.

The Maven run starts. The execution logs display in the console. After the run is complete, make sure the BUILD SUCCESS message is at the end of the log in the console, if not, there are errors to fix. Figure 9 shows the console of a successful Maven execution result of portlet as an EAR deployment.

Figure 9. Maven execution result
Snapshot of Maven execution results
Snapshot of Maven execution results

To verify that the portlet deployed to the WebSphere Portal Server, search for it in the portal administrator console. You can see how it rendered by placing the portlet in a portal page.

Summary

In this article you learned how to create a multi-module project in Rational Application Developer and then you published the same multi-module portlet project as an enterprise application project on WebSphere Portal Server using the IBM deployment plugin.


Downloadable resources


Related topics


Comments

Sign in or register to add and subscribe to comments.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=991084
ArticleTitle=Maven integration for portlet projects with IBM Rational Application Developer: Part 2. EAR deployment
publish-date=12022014