Tuesday 15 March 2022

Maven archetypes

Maven archetypes are the project templates, used to quickly setup the maven project. For example, maven simple archetype generate a project skelton like below.

 

 


Command to generate a project skelton using archetype

Syntax

mvn archetype:generate -DarchetypeGroupId={ARCHETYPE_GROUP_ID} -DarchetypeArtifactId={ARCHETYPE_ARTIFACT_ID} -DarchetypeVersion={ARCHETYPE_VERSION}

Example

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-simple -DarchetypeVersion=1.4

Let’s create a simple project skelton using ‘maven-archetype-simple’.

 

Step 1: Open terminal and execute the below command.

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-simple -DarchetypeVersion=1.4

This command starts in interactive mode, you need to provide 'groupId', 'artifactId', 'version'  and  'package' details to proceed further.

Define value for property 'groupId': com.sample.app
Define value for property 'artifactId': hello-world
Define value for property 'version' 1.0-SNAPSHOT: : 1.0.0
Define value for property 'package' com.sample.app: : 
Confirm properties configuration:
groupId: com.sample.app
artifactId: hello-world
version: 1.0.0
package: com.sample.app
 Y: : Y

Once the command executed successfully, you can see a project like below gets created.

$tree hello-world/
|____
| |____pom.xml
| |____src
| | |____test
| | | |____java
| | | | |____com
| | | | | |____sample
| | | | | | |____app
| | | | | | | |____AppTest.java
| | |____site
| | | |____site.xml
| | |____main
| | | |____java
| | | | |____com
| | | | | |____sample
| | | | | | |____app
| | | | | | | |____App.java

You may like

Add new Archetype in Eclipse: https://self-learning-java-tutorial.blogspot.com/2015/08/add-new-maven-archetype-in-eclipse.html

 

References

https://maven.apache.org/guides/introduction/introduction-to-archetypes.html

https://maven.apache.org/archetypes/maven-archetype-simple/





Previous                                                 Next                                                 Home

No comments:

Post a Comment