EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Maven Tutorial Maven Archetype
Secondary Sidebar
Maven Tutorial
  • Maven Basic and advance
    • What is Maven
    • How to Install Maven
    • Maven Commands
    • Maven GroupId
    • Maven WAR Plugin
    • Maven Build Command
    • Maven Failsafe Plugin
    • Maven Profile
    • IntelliJ Maven
    • Maven Enforcer Plugin
    • Maven Javadoc Plugin
    • Maven WAR Plugin
    • Maven Build Command
    • Maven GroupId
    • Maven Force Update
    • Maven Encrypt Password
    • Maven Environment Variables
    • AssertJ Maven
    • Maven Run Single Test
    • Maven kafka-clients
    • Maven Quickstart Archetype
    • Maven Install Dependencies
    • Maven XMLBeans
    • Maven Local Repository
    • Maven Versions
    • Maven Jar Plugin
    • Maven Assembly Plugin
    • Maven exec plugin
    • Maven Central Repository
    • Maven Surefire
    • Maven Deploy
    • Maven Phases
    • Maven Archetype
    • Maven Skip Test
    • Maven Dependency Scope
    • Maven Shade Plugin
    • Maven Repository Spring
    • Maven Eclipse Plugin
    • Maven Exclude Dependency
    • Maven Life Cycle
    • Maven Repository
    • Maven POM File
    • Maven Plugins
    • What is Maven Plugins
    • Maven Interview Questions
    • Maven Flags
    • Maven Project
    • Maven Settings.XML

Maven Archetype

By Payal UdhaniPayal Udhani

Maven Archetype

Introduction to Maven Archetype

Maven is a project management tool and archetype is the toolkit that helps to define the project templates. The archetype can also be considered as the model or pattern that is defined and that can be used further to generate other things in the same manner. These new creations follow the same template structure. These projects help the developers by providing a consistent pattern that comprises of the best practices for creating the project and to generate their projects with parameterized versions of the templates of the project with the help of using the archetypes.

We can even create our artifacts and define our template structure to be followed in the project or organizations. Besides this, there are many archetypes provided by maven providing templates for different project purposes. Also, if such templates are used, it will be easier to work with the projects for new developers as the structure is consistent and understandable due to segregation.

Additive Nature of Archetypes

The archetype facility provided by the maven is additive. That means we can add the new portions and aspects or pieces of the project to the existing project. To give an example of the above statement consider that you have created a quickstart archetype template’s project and then in the future, you felt the necessity to have the site for the project. In this case, it is very easy to inculcate the site model in the existing project with the help of the site archetype. We can perform such operations if we use the archetypes in our project.

Sharing the created archetype across the organization

Suppose, that your organization or company wants to create a project using J2EE standards and a provision for the web services containing EJBs or WARs is to be provided in the archetype or template of the project. You can create such an archetype and then deploy it to the remote repository of your organization so that this archetype is available for users to all other developers and members working in your organization.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Available Archetypes

Maven tool provides us with many in-built archetype artifacts that can be used by us for our projects. Depending upon the type of the project, technologies, languages, and domain of our project, we can choose the artifact that we want to use for generating our project. If none of the available fits or you want to use your self-defined archetype, you can create an archetype.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,502 ratings)

To list out all the artifact Ids archetypes present in the maven, you can fire the following command on your terminal –

mvn archetype: generate

This command is used to create a new project with the specified archetype and is the goal available in maven. But as we are not mentioning any artifactid or number equivalent to a particular id, it will display the list of the artifacts of archetype available in your installed version on the terminal and ask for entering the number of the artifact id of the archetype whose template is to be used for creating your project. You can exit your command prompt to skip project creation by using the Ctrl+Z command on UNIX/Linux and Ctrl+c on the windows machine. The output of the above command is too lengthy but I will share with you the start and end portion of it which is somewhat like following –

maven archetype output 1

maven archetype output 2

The above output shows that 2690 artifact ids are corresponding to the archetypes available in maven. Alternatively, you can export the resultset of the command into a file to view the archetype list available by using the following command –

mvn archetype:generate > listOfArchetypes.txt

Firing will result in the creation of a new file named listOfArchetypes that will contain the list of archetypes available.

Some of the available and most often used artifacts are listed below –

Artifact Id of archetype Usage
Maven-archetype-archetype artifactid This artifact id is used to create a sample archetype project using maven.
Maven-archetype-site-simple artifactid This artifact id is used to create a sample maven site using maven.
Maven-archetype-webapp artifactid This artifact id is used to create a sample webappmaven project.
Maven-archetype-plugin artifactid This artifact id is used to create a sample maven plugin.
Maven-archetype-quickstart artifactid This artifact id is used to create a sample project using maven.
Maven-archetype-portlet artifactid This artifact id is used to create a sample JSR-268 Portlet using maven.
Maven-archetype-site artifactid This artifact id is used to create a sample maven site consisting of some of the supported types of documents such as Xdoc, FML, and APT and help in guiding how to i18n your maven site.
Maven-archetype-plugin-site artifactid This artifact id is used to create a sample plugin site using maven.
Maven-archetype-j2ee-simple artifactid This artifact id is used to create a sample J2EE application project using maven.
Maven-archetype-mojo artifactid This artifact id is used to create a sample maven plugin.
Maven-archetype-simple artifactid This artifact id is used to create a simple maven project.

Maven Archetype Creation

If you want to create your archetype, you can do so by following certain simple steps. An archetype is itself a normal project along with some extra content that is as follows –

  • src/main/resources/archetype-resources – This is the directory from where the archetype i.e template resources are copied while creating a new project of the current archetype.
  • src/main/resources/META-INF/maven/archetype-metadata.xml – This file stores the description of the metadata of the archetype.

We can create a new archetype by using the archetype-maven-plugin and then modifyu=ing the contents of the above two mentioned things of archetype archetype-resources directory and archetype-metadata.xml file.

Fire the following command to create a new archetype –

mvn archetype:generate -B -DarchetypeArtifactId=maven-archetype-archetype \
-DarchetypeGroupId=maven-archetype \
-DgroupId=com.educba \
-DartifactId=test-archetype

Alternatively, we can create a normal project and add these two things in it to create an archetype. To create archetype from the existing project you can make the use of the following goal and fire the command –

mvn archetype:create-from-project

The general structure of the archetype is as shown below –

Maven Archetype Creation

Conclusion – Maven Archetype

We can create the maven project of a particular archetype. Archetypes are just the template or structure defining how the project should be created. There are many available archetypes for different usages. If you want to create a new archetype, you can do so and even share it with your organization by deploying it on a remote server of your organization.

Recommended Articles

This is a guide to Maven Archetype. here we discuss how the maven project should be created along with the available archetypes for different usages. You may also look at the following articles to learn more –

  1. Maven Repository
  2. What is Maven
  3. What is Maven Plugins?
  4. Install Maven
Popular Course in this category
Maven Training (4 Courses, 6 Projects)
  4 Online Courses |  6 Hands-on Project |  26+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more