![]() |
VOOZH | about |
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.
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.
There are two ways to create a Maven project using the CLI:
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).
For a typical Java project, you can choose maven-archetype-quickstart. The ID for this archetype is usually 2158.
Provide Details: Maven will ask for the following details:
Change to the Directory which you stored Project:
cd maven-artifact
You can see the project using the
maven-artifact> ls
With the help of these command we can see the structure of the project in the command Prompt
maven-artifact> tree
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:
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