🍃Maven Archetype
Describe about Maven Archetype
Maven Archetype is a Maven project templating toolkit that we can use to create our own custom template of the project (Think as a Image) , Then this image will be used to generate the project.
Advantage
Reduce time when we need to initialize new project
Have a standard project structure when we work with multiple team.
Component
Archetype Descriptor = Configure
selected filethat we want to use for generate in archetype and define which folder istest folderorcode folder. The location is insrc/main/resources/META-INF/maventhat consist ofarchetype.xmlorarchetype-metad.xml
Example:
// Example
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</fileSet>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/test/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSets> Prototype file = Store the code and configuration. The location is in
src/main/resources/archetype-resourcesPom for generate project = Pom for generated project from archetype. The location is in
src/main/resources/archetype-resourcesPom for archetype = It is root level of archetype project or target folder ( If archetype is created from existing project )
How to create new project from archetype ?
use this command to generate the project
mvn archetype:generate \
-DarchetypeGroupId=<archetype-group-id> \
-DarchetypeArtifactId=<archetype-artifact-id> \
-DarchetypeVersion=<archetype-version> \
-DgroupId=<new-project-group-id> \
-DartifactId=<new-project-artifact-id> \
-Dversion=<new-project-version> There are 2 way to create own archetype
Create new archetype project. ( can use maven archetype plugin to generate sample code)
Create archetype from existing project
How to create archetype from existing project ?
Run command
mvn archetype:create-from-project(You can add -X to debug If error occured to debug)
If you found some issue maybe you need to create the settings.xml in .m2
ref: https://stackoverflow.com/questions/59603307/calling-mvn-archetypecreate-from-project-on-a-simple-archetypewebapp-project-i
Verify correctness of code in
target/generated-sources/archetype/src/main/resources/archetype-resourcesNavigate to folder
target/generated-sources/archetypeand run commandmvn clean installDouble check in
.m2/repositorywhether the archetype is created or not.
For more information you can learn in this repository: https://github.com/brightkut/zeldra
Last updated