Create a New Maven Project from Command Prompt (original) (raw)

Last Updated : 9 Jan, 2026

In this guide, we will learn how to create a new Maven project using the Command Line Interface (CLI). Maven is a powerful build automation tool that simplifies project management, especially for Java projects. There are different ways to create a Maven project, including using an Integrated Development Environment (IDE) or the CLI. This article will focus on the CLI method.

Prerequisites

Before creating a Maven project, ensure the following prerequisites are met:

mvn -version

You should see output indicating the Maven version, Maven home, and the Java version being used.

Creating a Maven Project Using CLI

There are two ways to create a Maven project using the CLI:

  1. Interactive Mode
  2. Non-Interactive Mode.

Method 1: Interactive Mode

In interactive mode, Maven prompts you for input during the project creation process. Follow these steps:

mvn archetype:generate

Maven will prompt you to select an archetype (template).

Maven in Interactive Mode

Maven in Interactive Mode

For a typical Java project, you can choose maven-archetype-quickstart. The ID for this archetype is usually 2158.

choose maven-archetype-quickstart

choose maven-archetype-quickstart

**Provide Details: Maven will ask for the following details:

Provide Details

Provide Details

Generate the project structure by Interactive Mode in maven

Generate the project structure by Interactive Mode in maven

**Change to the Directory which you stored Project:

cd maven-artifact

**You can see the project using the

maven-artifact> ls

Screenshot-2024-11-14-162054

maven-artifact> ls -Command Output

With the help of these command we can see the structure of the project in the command Prompt

maven-artifact> tree

Screenshot-2024-11-14-164901

maven-artifact> tree Command Output

Method 2: Non-Interactive Mode

In non-interactive mode, all details are provided in a single command, which automates the process without further input. Follow these steps:

**Open Command Prompt: Open your command prompt or terminal.

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

**Run the Command with Parameters: Use the following command, replacing the placeholders with your desired values:

Run the Command with Parameters

Run the Command with Parameters

Maven will create the project without prompting for additional input.

With the help of these commands we will see the Structure of the project

maven-artifact> tree

maven-artifact> tree Command Output

maven-artifact> tree Command Output