Multi-module Websphere web application

  1. Introduction
  2. Maven project structure
  3. Source code

Introduction

This article describes how to create a Spring web application that can be deployed on the WebSphere application server. The goal is to create a maven project that can be used to generate an EAR file.

Maven project structure

The following list shows the multi-module maven project directory structure:

|- websphere-maven-spring-project 
|-- app-ear/
|---- pom.xml
|-- app-webapp/
|---- src/
|---- .classpath
|---- pom.xml
|- pom.xml

The project consists of one parent/aggregator module and two sub/child modules. For more information on multi-module please go to maven documentation website.

Aggregator module

The aggregator is a top-level module used to join multiple modules.

The following is an excerpt from aggregator pom.xml:

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.svlada</groupId>
  <artifactId>app</artifactId>
  <name>app</name>
  <version>1.0.0</version>
  <packaging>pom</packaging>
  <url>http://maven.apache.org</url>
  <modules>
    <module>app-ear</module>
    <module>app-webapp</module>
  </modules>

Sub-modules

Both sub-modules (app-ear and app-webapp) must include reference to the parent module as follows:

<parent>
	<artifactId>app</artifactId>
	<groupId>com.svlada</groupId>
	<version>1.0.0</version>
</parent>

Sub-module: app-ear

WAR module (app-webapp) needs to be included in the list of EAR dependencies.

<dependencies>
	<dependency>
		<groupId>com.svlada</groupId>
		<artifactId>app-webapp</artifactId>
		<version>1.0.0</version>
		<type>war</type>
	</dependency>
</dependencies>

Include maven-ear-plugin in the build plugins section of the app-ear pom.xml:

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-ear-plugin</artifactId>
	<version>2.10</version>
	<configuration>
		<finalName>APP_EAR</finalName>
		<modules>
			<webModule>
				<groupId>com.svlada</groupId>
				<artifactId>app-webapp</artifactId>
				<bundleFileName>app-webapp.war</bundleFileName>
				<contextRoot>/app</contextRoot>
			</webModule>
		</modules>
		<generateApplicationXml>true</generateApplicationXml>
	</configuration>

</plugin>

Sub-module: app-webapp

Web app module is an simple web application generated with the spring initializr.

Source code

You can clone entire project from the following github repository.