Updated February 20, 2023
Introduction to Maven Quickstart Archetype
Maven quickstart archetype is used to generate the maven sample project, by using the archetype we can create a new project. The maven quickstart archetype is nothing but a plugin whose work is to create the structure of the project as per the template which we have defined. We are using the maven quickstart archetype to create a simple java application. For creating the project by using the maven quickstart archetype we need to execute the mvn command.
Key Takeaways
- The maven archetype is nothing but a kind of project abstraction which was instantiated from the customized project of the maven.
- It is nothing but a template project from which we are creating another project. The main use of archetype in maven is we can standardize the development of the project.
What is Maven Quickstart Archetype?
Suppose we need to create a sample project by using the command line same time, we are using the maven quickstart archetype. While creating the project we need to pass the archetype generate parameter with the mvn command, it will create a new maven project. There are multiple types of archetypes available in maven for creating the project. For starting a new project, we need to use the maven archetype plugin from the command line. The archetype generates goal will select the default archetype which is suggested after pressing the enter key. Maven archetype plugin will be creating a directory name as simple which matches the artifactid.
How to Create Archetype?
For creating the archetype project first we need to create a console where we have installed mvn.
Below steps shows how we can create the archetype as follows:
1. In the first step we are opening the console where our mvn is installed. In the below example we have configured the maven command, so we have no need to find the specified maven path.
2. After opening the command shell now, we are executing the below command for creating the archetype project as follows. We are using the mvn command with archetype generate parameter as follows.
Command:
mvn archetype:generate
Output:
3. After executing the mvn archetype command, in this step we are choosing the default to apply filter. We are not entering anything so it will choose as default.
4. After defining the default option of archetype quickstart, now in this step we are choosing the version of archetype quickstart. In the below example, we can see that it will display the eighth version. While pressing enter it will be choosing the default version as 8.
5. After defining the version of the archetype in this step we are entering the details of the project. We are entering below the details of the project. We need to define the value of groupid, artifactid, version, and package as follows.
groupId – com.archetype
version – 1.0-SNAPSHOT
artifactId – maven_archetype
package – maven_archetype
6. After entering the details now in this step we are confirming all the details which we have entered as follows.
7. After entering all the details, after going into the project we can see that the maven_archetype project is created and all the files are created.
8. After checking the structure of the project in the below example we can see that the pom.xml file is also generated in the project directory.
9. After checking the pom.xml file in the below example we can see that the App.java file is created into the project folder as follows.
10. After checking the App.java file in the below example we can see that the AppTest.java file is created into the project folder as follows.
Using Archetype Project
The maven archetype plugin will be allowing us for users to create the maven project by using the archetype and generate goal. In the below example, we are creating the maven project by defining all the project values as follows. The below command will generate the maven project from our archetype as follows.
Command:
mvn archetype:generate –DarchetypeGroupId = com.archetype –DarchetypeArtifactId = archetype –DarchetypeVersion = 1.0-SNAPSHOT –DgroupId = com.archetype –DartifactId = archetype_sample –Dversion = 1.0-SNAPSHOT
Output:
We need to pass the archetype arguments with the maven archetype plugin for generating the archetype goal. We can also pass the project which was the archetype from which we are providing the archetype interactive mode. The maven archetype project is generated we can invoke the same by running the below command.
Code:
mvn package liberty:run
Output:
After generating the archetype project in the below example we are checking the pom.xml file of the project as follows.
Maven Quickstart Different Archetypes
There are multiple types of archetypes available in maven which are mentioned below.
- maven-archetype-archetype – This archetype contains the archetype which contains a sample project.
- maven-archetype-j2ee-simple – This archetype will contain the sample simplified application of J2EE.
- maven-archetype-mojo – This archetype will contain the maven plugin which is a sample in nature.
- maven-archetype-plugin-site – This archetype will contain the sample maven site of the plugin.
- maven-archetype-plugin – This archetype will contain the sample maven plugin which is used in the maven archetype project.
- maven-archetype-portlet – This archetype will contain the sample portlet of JSR 268.
- maven-archetype-quickstart – This archetype will contain the sample maven project which is developed using maven.
- maven-archetype-simple – This archetype will contain the simple maven project which is developed using maven.
- maven-archetype-site-sample – This archetype will contain the sample maven site.
- maven-archetype-webapp – This archetype will contain the sample maven webapps project.
- maven-archetype-site – This archetype will contain the sample maven site which was demonstrating the supporting documents like APT, FML, and XDOC which were demonstrated on our site.
Examples of Maven Quickstart Archetype
Given below are the examples mentioned:
Example #1
The below example shows the maven quickstart archetype as follows. We are using a simple generate parameter for creating the project by using maven quickstart. We are entering below details of the project, we are defining the value of groupid, artifactid, version, and package as follows.
mvn archetype:generate
groupId – com.maven
version – 1.0-SNAPSHOT
artifactId – archetype
package – archetype
Example #2
In the below example, we are defining all the parameters as the time of executing the maven generate command as follows.
Command:
mvn archetype:generate –DarchetypeGroupId = com.maven –DarchetypeArtifactId = maven –DarchetypeVersion = 1.0-SNAPSHOT –DgroupId = com.maven –DartifactId = maven_sample –Dversion = 1.0-SNAPSHOT
Output:
FAQ
Given below are the FAQs mentioned:
Q1. What is the use of maven quickstart archetype?
Answer: Basically, maven quickstart archetype is used to create the maven project. It will create all the structure of the maven project. We can develop a sample application by using archetypes.
Q2. Which plugin do we need to use while creating a project using the maven archetype?
Answer: We need to use the archetype plugin while developing the application by using maven archetype quickstart.
Q3. What is the use of the maven archetype descriptor while creating the project?
Answer: The descriptor of the maven archetype is the heart of the archetype project. It is an xml file name archetype-metadata.xml located in the project directory.
Conclusion
Archetype generates a goal that selects the default archetype which is suggested after pressing the enter key. Maven archetype plugin will be creating a directory name as simple which matches the artifactid. Maven quickstart archetype is nothing but a plugin whose work is to create the structure of the project as per the template, we have defined.
Recommended Articles
This is a guide to Maven Quickstart Archetype. Here we discuss the introduction, how to create Archetype? and maven quickstart different archetypes and examples. You may also have a look at the following articles to learn more –