Maven - SPLessons

Maven Web Application

Chapter 15

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Maven Web Application

Maven Web Application

shape Introduction

In previous tutorials, projects were developed using maven archetypes, plug-ins, etc. Now, with templates, Maven Web Application can be created using the Webapp plug-in. The present chapter explains about webapp plug-in and how to create a sample Maven Web Application.

Webapp Plugin

shape Description

Normally, J2EE applications have WEB-INF folder, which consists of web.xml. web.xml files are called as Deployment Descriptor files that are used for servlets configurations as web.xml helps in:

Maven Archetype Webapp plug-in creates the default file structure for the application.

shape Step-1

Open the command prompt and create a folder where the project has to be saved. Now, copy the below command in command prompt under the created folder as shown.

mvn archetype:generate -DgroupId=com.sample.webproject -DartifactId=WebApplication -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

By creating the required files for building an application, following output appears.

By this, Maven also creates a web application structure with the application name WebApplication. The project structure in eclipse is as follows:

shape Step-2

Check for pom.xml and index.jsp file that has the following codes by default.


<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
  <name>WebApplication Maven Webapp</name>



<h2>Hello World!</h2>


Building WebApp

shape Step-3

Again open the command prompt, go to the root folder, enter the mvn clean package command and click enter to compile, test and create the WAR file for the project.

The following output appears.

shape Step-4

One can view the WebApplication.war in target folder. Now, deploy that war file into the server. The following output appears that shows that the application has been created successfully.


shape Key Points

  • Webapp plug-in is required to generate the web applications in Maven.
  • Web application is build using the mvn clean package command.

shape Programming

Make sure to deploy the generated war file into the server target folder.