Site icon Automation Dojos

How To Create Maven Project in Eclipse With Archetype

Maven Basics

Maven automates the steps involved in building a software application like adding the JAR files, compiling code, running unit tests, creating the output jar/war file, etc. This makes the code less error-prone. Maven uses an XML configuration file known as the POM file. Developers need to specify information like the JAR files required by an application, the type of output artifact (jar,war, etc). Maven then uses the instructions in the POM file to build the application.

Eclipse Maven Integration

Most of the recent Eclipse releases already include Maven. So, developers do not need to do anything special to install Maven in Eclipse.  However, some earlier versions of Eclipse do not include Maven, so it needs to be installed explicitly from the Eclipse marketplace. Once Maven is set up with Eclipse, it allows you to easily create a Maven project and use all the Maven features like dependency resolution within Eclipse itself.

Create Maven Project with Archetype in Eclipse

Maven archetype provides a template that can be used to create a particular type of Maven project. If a Maven project is created with an archetype selection, Maven creates the POM file accordingly. Some of the common Maven archetypes are as follows:

  • maven-archetype-quickstart – Can be used to create a basic Maven project
  • maven-archetype-j2ee-simple – Can be used to create a simple j2ee project
  • maven-archetype-webapp – Can be used to create a web application

In order to create a Maven project with a webapp archetype, the following steps need to be followed:

Create new artefact of type ‘Other’

On Eclipse main menu, navigate to ‘File > New’ and select ‘Other’

Select Maven Project

Select the option ‘Maven Project’ and click Next.

Uncheck ‘Create Simple Project

Leave the Create a Simple Project (skip archetype selection) checkbox unchecked. Click Next

Use filter ‘maven-archetype-webapp

Select maven-archetype-webapp.

Input Group Id and Artifact Id

Enter a value for Group Id and Artifact Id. Change version and package if required. Click Finish

Verify New Maven project in Eclipse

This creates a Maven project in Eclipse with the Maven directory structure and POM file as follows

Finish!

Finish! This POM file can then be modified by adding dependencies and other information as required.

[td_smart_list_end]
Exit mobile version