- Maven - Home
- Maven - Overview
- Maven - Environment Setup
- Maven - POM
- Maven - Build Life Cycle
- Maven - Build Profiles
- Maven - Repositories
- Maven - Plug-ins
- Maven - Creating Project
- Maven - Build & Test Project
- Maven - External Dependencies
- Maven - Project Documents
- Maven - Project Templates
- Maven - Snapshots
- Maven - Build Automation
- Maven - Manage Dependencies
- Maven - Deployment Automation
- Maven - Web Application
- Maven - Eclipse IDE
- Maven - NetBeans
- Maven - IntelliJ IDEA
Maven Useful Resources
Maven - Project Templates
Maven provides users, a very large list of different types of project templates (614 in numbers) using the concept of Archetype. Maven helps users to quickly start a new java project using the following command.
mvn archetype:generate
What is Archetype?
Archetype is a Maven plugin whose task is to create a project structure as per its template. We are going to use quickstart archetype plugin to create a simple java application here.
Using Project Template
Let's open the command console, go to the D:\Projects\MVN directory and execute the following mvn command.
D:\Projects\MVN>mvn archetype:generate
Maven will start processing and will ask to choose the required archetype.
D:\Projects\MVN>mvn archetype:generate [INFO] Scanning for projects... [INFO] [INFO] ------------------< org.apache.maven:standalone-pom >------------------- [INFO] Building Maven Stub Project (No POM) 1 [INFO] --------------------------------[ pom ]--------------------------------- [INFO] [INFO] >>> maven-archetype-plugin:3.2.0:generate (default-cli) > generate-sources @ standalone-pom >>> [INFO] [INFO] <<< maven-archetype-plugin:3.2.0:generate (default-cli) < generate-sources @ standalone-pom <<< [INFO] [INFO] [INFO] --- maven-archetype-plugin:3.2.0:generate (default-cli) @ standalone-pom --- [INFO] Generating project in Interactive mode [INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) Choose archetype: 1: remote -> am.ik.archetype:elm-spring-boot-blank-archetype (Blank multi project for Spring Boot + Elm) 2: remote -> am.ik.archetype:graalvm-blank-archetype (Blank project for GraalVM) ... 3580: remote -> za.co.absa.hyperdrive:component-archetype_2.12 (-) Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 2268:
Press Enter to choose to default option (2268: maven-archetype-quickstart)
Maven will ask for particular version of archetype.
Choose org.apache.maven.archetypes:maven-archetype-quickstart version: 1: 1.0-alpha-1 2: 1.0-alpha-2 3: 1.0-alpha-3 4: 1.0-alpha-4 5: 1.0 6: 1.1 7: 1.3 8: 1.4 9: 1.5 Choose a number: 9:
Press Enter to choose to default option (9: maven-archetype-quickstart:1.5)
Maven will ask for the project detail. Enter project detail as asked. Press Enter if the default value is provided. You can override them by entering your own value.
[INFO] Using property: javaCompilerVersion = 17 [INFO] Using property: junitVersion = 5.11.0 Define value for property 'groupId': com.companyname.insurance Define value for property 'artifactId': health Define value for property 'version': 1.0-SNAPSHOT: Define value for property 'package': com.companyname.insurance:
Maven will ask for the project detail confirmation. Press enter or press Y.
Confirm properties configuration: javaCompilerVersion: 17 junitVersion: 5.11.0 groupId: com.companyname.insurance artifactId: health version: 1.0-SNAPSHOT package: com.companyname.insurance Y:
Now Maven will start creating the project structure and will display the following −
[INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating project from Archetype: maven-archetype-quickstart:1.5 [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: com.companyname.insurance [INFO] Parameter: artifactId, Value: health [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: package, Value: com.companyname.insurance [INFO] Parameter: packageInPathFormat, Value: com/companyname/insurance [INFO] Parameter: junitVersion, Value: 5.11.0 [INFO] Parameter: package, Value: com.companyname.insurance [INFO] Parameter: groupId, Value: com.companyname.insurance [INFO] Parameter: artifactId, Value: health [INFO] Parameter: javaCompilerVersion, Value: 17 [INFO] Parameter: version, Value: 1.0-SNAPSHOT [WARNING] Don't override file D:\Projects\MVN\health\src\main\java\com\companyname\insurance [WARNING] Don't override file D:\Projects\MVN\health\src\test\java\com\companyname\insurance [WARNING] CP Don't override file D:\Projects\MVN\health\.mvn [INFO] Project created from Archetype in dir: D:\Projects\MVN\health [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 17.830 s [INFO] Finished at: 2025-09-15T14:15:27+05:30 [INFO] ------------------------------------------------------------------------
Created Project
Now go to D:\Projects\MVN\ directory. You'll see a java application project created, named health, which was given as artifactId at the time of project creation. Maven will create a standard directory layout for the project as shown below −
Created POM.xml
Maven generates a POM.xml file for the project as listed below −
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.companyname.insurance</groupId>
<artifactId>health</artifactId>
<version>1.0-SNAPSHOT</version>
<name>health</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<!-- Optionally: parameterized tests support -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.6.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Created App.java
Maven generates sample java source file, App.java for the project as listed below −
Location: src > main > java > com > companyname > insurance > App.java.
package com.companyname.insurance;
/**
* Hello world!
*
*/
public class App {
public static void main( String[] args ) {
System.out.println( "Hello World!" );
}
}
Created AppTest.java
Maven generates sample java source test file, AppTest.java for the project as listed below −
Location: src > test > java > com > companyname > insurance > AppTest.java.
package com.companyname.insurance;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest extends TestCase {
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName ) {
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite() {
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp() {
assertTrue( true );
}
}
Now you can see the power of Maven. You can create any kind of project using single command in maven and can kick-start your development.
Different Archetypes
| Sr.No. | Archetype ArtifactIds & Description |
|---|---|
| 1 |
maven-archetype-archetype An archetype, which contains a sample archetype. |
| 2 |
maven-archetype-j2ee-simple An archetype, which contains a simplified sample J2EE application. |
| 3 |
maven-archetype-mojo An archetype, which contains a sample a sample Maven plugin. |
| 4 |
maven-archetype-plugin An archetype, which contains a sample Maven plugin. |
| 5 |
maven-archetype-plugin-site An archetype, which contains a sample Maven plugin site. |
| 6 |
maven-archetype-portlet An archetype, which contains a sample JSR-268 Portlet. |
| 7 |
maven-archetype-quickstart An archetype, which contains a sample Maven project. |
| 8 |
maven-archetype-simple An archetype, which contains a simple Maven project. |
| 9 |
maven-archetype-site An archetype, which contains a sample Maven site to demonstrates some of the supported document types like APT, XDoc, and FML and demonstrates how to i18n your site. |
| 10 |
maven-archetype-site-simple An archetype, which contains a sample Maven site. |
| 11 |
maven-archetype-webapp An archetype, which contains a sample Maven Webapp project. |