September 10, 2015 · maven websphere java spring

Maven project for creating Spring web applications deployable on Websphere

Table of contents:

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

Introduction

I have created simple boilerplate maven project that can be used as a starting point when developing Spring based web applications that can be deployed in a WebSphere application server.

Goal is to to create maven project that can generate deployable EAR File for server deployment.

Maven project structure

Following is the multi-module maven project directory structure:

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

Project have one parent/aggregator module and two sub/child modules. More information regarding multi-module can be found on the maven documentation website.

Aggregator module

Aggregator is a top-level module serving for joining multiple modules under one level is called aggregator.

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 parent module as follows:

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

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>  

The maven-ear-plugin needs to be included 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>  

app-webapp

Spring Project is used to generate app-webapp web maven project.

Source code

I have shared project source code on following location on github.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket
Comments powered by Disqus