Friday, December 20, 2013

How to create WAR file using Maven ?

In this post we will see how to create WAR (Web ARchive) using Apache Maven. And we will also see how this pom.xml flow is created!!

What is the real meaning of Maven?

A Person particularly very skilled in their field is normally called as “Maven”, as similar to that, this build tool developed by Apache foundation “Maven” is also more knowledgeable due to the following 2 important reasons.
1] It simplifies the Project dependencies
2] It simplifies the Project structure creation for various Artifacts

What are the default targets executed by Maven?

The following core Plugins executed as default by maven.
clip_image002

Please see the attached Maven Web Application execution output snapshot for detailed introspection.

clip_image004

myearproject-dhoni-web pom.xml:

<?xml version="1.0" encoding="UTF-8"?>

<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>

<artifactId>myearproject</artifactId>

<groupId>com.mycompany</groupId>

<version>1.0-SNAPSHOT</version>

</parent>

<groupId>com.mycompany</groupId>

<artifactId>myearproject-dhoni-web</artifactId>

<packaging>war</packaging>

<version>1.0-SNAPSHOT</version>

<name>myearproject-dhoni-web</name>

<url>http://maven.apache.org</url>

<dependencies>

<dependency>

<groupId>javax</groupId>

<artifactId>javaee-web-api</artifactId>

<version>6.0</version>

<scope>provided</scope>

</dependency>

</project>

As mentioned in the <packaging></packaging> section of the POM xml file maven generates the WAR artifact for the specified project.

clip_image006

These figured displays above are the list of packaging type supported that supported by Maven. Forget to mention, there is one more packaging type that supported by Multi-module project, that’s “pom” packaging type.

References:

1] http://maven.apache.org/plugins/

No comments:

Post a Comment