Project Templates
Maven uses archetypes to create custom project structures, forming Maven project templates.
In the previous chapter we learned that Maven uses the following command to quickly create java project:
mvn archetype:generate
* * *
## What is an archetype?
An archetype is a Maven plugin, or more precisely a project template, whose task is to create a project structure based on the template. We will use the quickstart archetype plugin to create a simple java application.
* * *
## Using Project Templates
Let us open the command console, go to the C:> MVN directory and execute the following mvn command:
C:MVN> mvn archetype:generate
Maven will start processing and ask you to select the desired archetype:
Scanning for projects... Searching repository for plugin with prefix: 'archetype'. ------------------------------------------------------------------- Building Maven Default Projecttask-segment: [archetype:generate] (aggregator-style) ------------------------------------------------------------------- Preparing archetype:generate ...600: remote -> org.trailsframework:trails-archetype (-)601: remote -> org.trailsframework:trails-secure-archetype (-)602: remote -> org.tynamo:tynamo-archetype (-)603: remote -> org.wicketstuff.scala:wicket-scala-archetype (-)604: remote -> org.wicketstuff.scala:wicketstuff-scala-archetype Basic setup for a project that combines Scala and Wicket, depending on the Wicket-Scala project. Includes an example Specs test.)605: remote -> org.wikbook:wikbook.archetype (-)606: remote -> org.xaloon.archetype:xaloon-archetype-wicket-jpa-glassfish (-)607: remote -> org.xaloon.archetype:xaloon-archetype-wicket-jpa-spring (-)608: remote -> org.xwiki.commons:xwiki-commons-component-archetype (Make it easy to create a maven project for creating XWiki Components.)609: remote -> org.xwiki.rendering:xwiki-rendering-archetype-macro (Make it easy to create a maven project for creating XWiki Rendering Macros.)610: remote -> org.zkoss:zk-archetype-component (The ZK Component archetype)611: remote -> org.zkoss:zk-archetype-webapp (The ZK wepapp archetype)612: remote -> ru.circumflex:circumflex-archetype (-)613: remote -> se.vgregion.javg.maven.archetypes:javg-minimal-archetype (-)614: remote -> sk.seges.sesam:sesam-annotation-archetype (-)Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 203:
Press **Enter** to select the default option (203:maven-archetype-quickstart).
* * *
## Maven will ask for archetype version
Choose org.apache.maven.archetypes:maven-archetype-quickstart version:1: 1.0-alpha-12: 1.0-alpha-23: 1.0-alpha-34: 1.0-alpha-45: 1.06: 1.1Choose a number: 6:
Press **Enter** to select the default option (6:maven-archetype-quickstart:1.1)
Maven will ask for project details. Please enter the project details. Press Enter to accept the default value. You can also enter your own values.
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 confirmation of the project details, press **Enter** or press Y
Confirm properties configuration: groupId: com.companyname.insurance artifactId: health version: 1.0-SNAPSHOT package: com.companyname.insurance Y:
Now Maven will start creating the project structure, showing the following:
----------------------------------------------------------------------- Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.1 ----------------------------------------------------------------------- Parameter: groupId, Value: com.companyname.insurance Parameter: packageName, Value: com.companyname.insurance Parameter: package, Value: com.companyname.insurance Parameter: artifactId, Value: health Parameter: basedir, Value: C:MVN Parameter: version, Value: 1.0-SNAPSHOT project created from Old (1.x) Archetype in dir: C:MVNhealth ----------------------------------------------------------------------- BUILD SUCCESSFUL ----------------------------------------------------------------------- Total time: 4 minutes 12 seconds Finished at: Fri Jul 13 11:10:12 IST 2012 Final Memory: 20M/90M -----------------------------------------------------------------------
* * *
## Created Project
Now go to C: > MVN directory. You will see a java application project named health, which was created with the artifactId name during project creation. Maven will create a project with standard directory layout as follows:
!(#)
* * *
## Create pom.xml
Maven automatically generates a pom.xml file for the project as
YouTip