Open In App

How to Create a Maven Project in IntelliJ IDEA?

Maven is a powerful project management tool based on POM (project object model). It is used for project build, dependency, and documentation. It simplifies the build process like ANT. But it is too much advanced than ANT. In the short term, we can tell maven is a tool that can build and manage any Java-based project. maven makes the day-to-day work of Java developers easier and generally helps with the comprehension of any Java-based project. Read more about maven here: Introduction to Apache Maven

In this article, we are going to explain how to create a maven project in IntelliJ IDEA. IntelliJ is an integrated development environment(IDE) written in Java. It is used for developing computer software. This IDE is developed by Jetbrains and is available as an Apache 2 Licensed community edition and a commercial edition.



Prerequisite: Refer to this article and install IntelliJ IDEA on your local machine: Step by Step guide to install Intellij Idea

Step By Step Implementation

Step 1: Open your IntelliJ IDE, and go to the File > New > Project as shown in the below image.



 

Step 2: On the next screen 

And if you check the “Add sample code” box then a simple Main class will be generated with the main() method inside. And if you open the Advance setting then you can also modify your GroupId and ArtifactId as shown in the below image. 

Note: Maven uses a set of identifiers, also called coordinates, to uniquely identify a project and specify how the project artifact should be packaged:

  • GroupId: a unique base name of the company or group that created the project
  • ArtifactId: a unique name of the project

And finally, click on the Create button. And you are done. 

 

After successfully creating the project you can see there are two default files have been created. 

pom.xml file:




<?xml version="1.0" encoding="UTF-8"?>
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <modelVersion>4.0.0</modelVersion>
  
    <groupId>org.gfg</groupId>
    <artifactId>gfgdemo</artifactId>
    <version>1.0-SNAPSHOT</version>
  
    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
  
</project>

Main.java class:




package org.gfg;
  
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}

Refer to the below image. 

 

Create Maven Project in IntelliJ IDEA from Maven Archetype

If you want to create a project from Maven Archetype then you can select the Maven Archetype from the Generators and choose the required Archetype from the menu as shown in the below image. 

Note: Archetype is a templating toolkit. It provides a templating solution for your project and helps to create a sample project structure that you can extend based on your business requirements.

 


Article Tags :