Maven Project Templates
Maven project templates are predefined project structures or archetypes that help you quickly generate a new Maven project with a standard setup. These templates are known in Maven as archetypes.
What is a Maven Archetype?
A Maven archetype is a template toolkit that allows you to generate a new Maven project with:
Standard folder structure (
src/main/java,src/test/java, etc.)A basic
pom.xmlSample source and test files (if provided)
Optional configurations (example: web app setup)
| Archetype | Description |
|---|---|
| maven-archetype-quickstart | Basic Java project with one class and one test class |
| maven-archetype-webapp | Web application project with web.xml and web folder structure |
| maven-archetype-j2ee-simple | Simple J2EE project setup |
| maven-archetype-site | For generating a project documentation website |
| maven-archetype-plugin | Template for creating a Maven plugin |
| maven-archetype-portlet | For creating Java portlet applications |
How to Use a Maven Template (Archetype)
Use the following command to create a new Maven project with a specific archetype:
mvn archetype:generate -DgroupId=com.example \ -DartifactId=my-app \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DinteractiveMode=false
Explanation:
groupId: The project group name (like a package)artifactId: The project namearchetypeArtifactId: The template to useinteractiveMode=false: Skip the interactive prompts
Benefits of Using Maven Archetypes
Saves time setting up boilerplate
Enforces standard structure and conventions
Useful for both beginners and experienced developers
Supports team consistency