You can create a new Maven project using the Maven Archetype Plugin. This plugin allows you to generate a basic project structure with common configurations and dependencies.
Steps to Create a New Maven Project:
-
Open your command line or terminal.
-
Navigate to the desired directory where you want to create your project.
-
Run the following command:
mvn archetype:generate
-
The command will prompt you to choose an archetype. You can search for specific archetypes by using the
-Dfilter
option. For example, to find Java web application archetypes:mvn archetype:generate -Dfilter=web
-
Select the desired archetype from the list.
-
Enter the required information, such as the project name, package name, and version.
-
Maven will create the project structure in the current directory.
Example: Creating a Simple Java Project
mvn archetype:generate -DgroupId=com.example -DartifactId=my-java-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
This command will create a simple Java project named "my-java-project" with the group ID "com.example".
Important Notes:
- Interactive Mode: By default, the
archetype:generate
command is interactive, prompting you to enter information. You can use the-DinteractiveMode=false
option to skip these prompts and use default values. - Archetype Catalog: The
archetype:generate
command uses the Maven archetype catalog to list available archetypes. You can find the list of available archetypes in the~/.m2/repository/org/apache/maven/archetypes/maven-archetype-catalog.xml
file. - Project Structure: The generated project structure will include a
pom.xml
file, source code directories, and other necessary files.
Conclusion:
Creating a new Maven project is a simple process using the Maven Archetype Plugin. By following these steps, you can quickly generate a basic project structure and get started with your development.