The MAVEN skeleton is implemented by the skeleton plug-in, and the entire skeleton flow is expressed in the entire flowchart in the following chart, the source of Maven's website.
maven Skeleton Introduction:
When you create a project using Mave, it is natural to use the skeleton of Maven's self, for example:
Maven Archetypes
Maven provides several achetype artifacts:
archetype Artifactids |
Description |
Maven-archetype-archetype |
An archetype to generate a sample archetype. |
Maven-archetype-j2ee-simple |
An archetype to generate a simplifed sample Java application. |
Maven-archetype-mojo (deprecated) |
Deprecated in favour of Maven-archetype-plugin, which has a better name. |
Maven-archetype-plugin |
An archetype to generate a sample Maven plugin. |
Maven-archetype-plugin-site |
An archetype to generate a sample Maven plugin site. |
Maven-archetype-portlet |
An archetype to generate a sample JSR-268 Portlet. |
Maven-archetype-quickstart |
An archetype to generate a sample Maven project. |
Maven-archetype-simple |
An archetype to generate a simple Maven project. |
Maven-archetype-site |
An archetype to generate a sample Maven site which demonstrates some of the supported document types like APT, Xdoc, and F ML and demonstrates to i18n your site. |
Maven-archetype-site-simple |
An archetype to generate a sample Maven site. |
Maven-archetype-webapp |
An archetype to generate a sample Maven Webapp project. |
Common such as: Maven-archetype-webapp,maven-archetype-simple.
The MAVEN skeleton plug-in all commands are as follows:
Plugin Documentation Goals available for this plugin:
Goal |
Description |
Archetype:crawl |
Crawl a Maven Repository (filesystem, not HTTP) and creates Acatalog file. |
Archetype:create |
deprecated. Please use the Generate Mojo instead. |
Archetype:create-from-project |
Creates a archetype project from the current project. This goal reads your source and resource files, the values ofits parameters, and properties for you specify in A.property file , and uses them to create a Mavenarchetype project using the Maven-archetype packaging. If you buildthe resulting project, it would create the archetype. Can thenuse this archetype to create new projects that resemble theoriginal. The maven-archetype-plugin uses velocity to expand Templatefiles, and this documentation talks about ' Velocity Properties ' , which are values substituted into Velocity templates. Seethevelocity User ' s Guide for more information. This goal modifies the "the" Current Projectto form the Velocity template files, make up the Archet Ype. GAV the GAV values for the current project are replaced Byproperties:groupid, Artifactid, and version. The user chooses NewValues for this is generating a project from the archetype. Package all of the files under one specified Java (or cognate) package arerelocated to a project this user chooses when G Enerating Aproject. References to the class name are replaced by a propertyreference. For example, if the current project ' s sources are in Thepackage org.apache.saltedpeanuts, then any example ofthe string or G.apache.saltedpeanuts is replaced withthe Velocity property Reference ${packagename}. Whenthe user generates a project, this is in turn replaced by his orher choice of a package. Custom properties you could identify additional strings that should to be replaced byparameters. To add custom properties, your must use the Propertyfile parameter to specify a PropeRty file. seethe documentation for Propertyfile for Thedetails. Note ' may need to edit ' results of this goal. Thisgoal has no way to exclude unwanted files, or add copyright Noticesto the Velocity templates, or add more complex elem Ents to Thearchetype metadata file. This is goal also generates a simple integration-test thatexercises the generated archetype. |
Archetype:generate |
Generates a new project from a archetype, or updates the actualproject if using a partial archetype. If The project is fullygenerated, it's generated in a directory corresponding to Itsartifactid. If the project is updated with a partial archetype, itis do in the current directory. |
Archetype:help |
Display Help information on Maven-archetype-plugin. Call MVN archetype:help-ddetail=true-dgoal=<goal-name> to display parameter details. |
Archetype:integration-test |
Execute the Archetype integration tests, consisting ingenerating projects from the current archetype and Optionallycompari Ng generated projects with reference copy. Each IT consists of a sub-directory insrc/test/resources/projects containing:a goal.txt file, containing a list of goals To runagainst the generated project (can is empty, content ignored Beforemaven-archetype-plugin 2.1), an Archetype.propert IES file, containingproperties for project Generation, a optional reference/directory containing copy of the Expected project created from the IT. Notice that it's expected to being run as part as the A build afterthe package phase and don't directly as a goal from CLI. |
Archetype:jar |
Build a JAR from the current archetype project. |
Archetype:update-local-catalog |
Updates the Local Catalog |
The first thing you do before you create your own skeleton is a command:
Archetype:generate
This command is useful for creating a MAVEN project from skeleton information.
$ MVN archetype:generate [INFO] scanning for projects ... [INFO]
Searching repository for plugin with prefix: ' Archetype '. [INFO]------------------------------------------------------------------------[INFO] Building Maven Default Project [INFO] task-segment: [Archetype:create] (Aggregator-style) [INFO]------------------------------------------ ------------------------------[INFO] Preparing archetype:generate [INFO] No goals needed for project-skipping [info] Se tting Property:classpath.resource.loader.class => '
Org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader '. [INFO]
Setting property:velocimacro.messages.on => ' false '. [INFO]
Setting property:resource.loader => ' classpath '. [INFO]
Setting property:resource.manager.logwhenfound => ' false '. [INFO]
[Archetype:generate] Choose archetype:1: Internal-> org.appfuse.archetypes:appfuse-basic-jsf (Appfuse archetype for creating a web Applica tion with Hibernate, Spring and JSF) 2:internal-> Org.appfuSe.archetypes:appfuse-basic-spring (Appfuse archetype for creating a Web application with Hibernate, Spring and spring MVC ) 3:internal-> org.appfuse.archetypes:appfuse-basic-struts (appfuse archetype for creating a Web application with Hib Ernate, Spring and Struts 2) 4:internal-> org.appfuse.archetypes:appfuse-basic-tapestry (appfuse archetype for Creati Ng a Web application with Hibernate, Spring and Tapestry 4) 5:internal-> Org.appfuse.archetypes:appfuse-core (appfuse Archetype for creating a jar application with Hibernate and Spring and XFire) 6:internal-> Org.appfuse.archetypes:ap PFUSE-MODULAR-JSF (AppFuse archetype for creating a modular application with Hibernate, Spring and JSF) 7:internal-> Org.appfuse.archetypes:appfuse-modular-spring (Appfuse archetype for creating a modular application with Hibernate, Spring and Spring MVC) 8:internal-> org.appfuse.archetypes:appfuse-modular-struts (appfuse archetype for creating a M Odular Application with HibernAte, Spring and Struts 2) 9:internal-> org.appfuse.archetypes:appfuse-modular-tapestry (appfuse archetype for Creatin G A modular application with Hibernate, Spring and Tapestry 4) 10:internal-> Org.apache.maven.archetypes:maven-archet Ype-j2ee-simple (A simple Java application) 11:internal-> org.apache.maven.archetypes: Maven-archetype-marmalade-mojo (A Maven plugin development project using marmalade) 12:internal-> Org.apache.maven.a Rchetypes:maven-archetype-mojo (A maven Java Plugin development project) 13:internal-> org.apache.maven.archetypes: Maven-archetype-portlet (A simple portlet application) 14:internal-> org.apache.maven.archetypes: Maven-archetype-profiles () 15:internal-> Org.apache.maven.archetypes:maven-archetype-quickstart () 16:internal- > org.apache.maven.archetypes:maven-archetype-site-simple (A Simple site Generation project) 17:internal-> Org.apache.maven.archetypes:maven-archetype-site (A more complex site project) 18:Internal-> Org.apache.maven.archetypes:maven-archetype-webapp (A simple Java Web application) 19:internal-> org. Apache.struts:struts2-archetype-starter (A starter Struts 2 application with Sitemesh, DWR, and Spring) 20:internal-> Org.apache.struts:struts2-archetype-blank (A minimal Struts 2 application) 21:internal-> org.apache.struts: Struts2-archetype-portlet (A minimal Struts 2 application, can be deployed as A portlet) 22:internal-> Org.apache
. Struts:struts2-archetype-dbportlet (A starter struts 2 portlet that demonstrates a simple CRUD interface with DB backing) 23:internal-> Org.apache.struts:struts2-archetype-plugin (a Struts 2 plugin) Choose A number or Apply filter (format : [Groupid:]artifactid, Case sensitive contains): 15:choose Org.apache.maven.archetypes:maven-archetype-quickstart Version:1:1.0-alpha-1 2:1.0-alpha-2 3:1.0-alpha-3 4:1.0-alpha-4 5:1.0 6:1.1 Choose a number:6: Define value for GroupId:: Com.company Define value foR Artifactid:: Project Define value for version:: 1.0 Define value for package:: Com.company.project Confirm Properties Configuration:groupId:com.company artifactid:project version:1.0 package:com.company.project Y:: [INFO]--------- -------------------------------------------------------------------[INFO] Using following parameters for creating Oldarchetype:maven-archetype-quickstart:release [INFO]--------------------------------------------------------- -------------------[INFO] parameter:groupid, Value:com.company [info] parameter:packagename, Value: Com.company.project [INFO] parameter:package, Value:com.company.project [info] parameter:artifactid, value:project [I NFO] Parameter:basedir, Value:/home/local/rafale/projects/tmp [info] parameter:version, value:1.0 [INFO] Oldarchetype Created in dir:/home/local/rafale/projects/tmp/project [INFO]---------------------------------------------------- --------------------[INFO] Build successful [info]------------------------------------------------------------------------[INFO] total time:54 seconds [info] finished At:fri Aug 26 23 : 01:01 GMT [INFO] Final memory:10m/25m [INFO]------------------------------------------------------------------ ------
It will allow you to select the Maven skeleton you need and then enter Groupid,packagename,package,artifactid,version. Then you create the MAVEN project in your directory.
create our own MAVEN skeleton based on our custom project, which is the second important command:
Archetype:create-from-projeCT
To customize the directory structure for your project:
Contents of the Pom file for this project:
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" >
< modelversion>4.0.0</modelversion>
<groupId>com.lgy.archetype-demo</groupId>
< artifactid>archetype-demo</artifactid>
<packaging>war</packaging>
<version> 1.0.0-release</version>
<name>archetype-demo Maven webapp</name>
<url>http:// maven.apache.org</url>
<dependencies>
<dependency>
<groupid>junit</ groupid>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>archetype-demo</finalName>
</build>
</project>
Note that the version type must be release
Go to the root of this project and execute the command:
MVN Archetype:create-from-project [INFO] scanning for projects ... [INFO]
Searching repository for plugin with prefix: ' Archetype '. [INFO]------------------------------------------------------------------------[INFO] building project [INFO] Task-segment: [Archetype:create-from-project] [INFO]------------------------------------------------------------ ------------[INFO] Preparing archetype:create-from-project [INFO] No goals needed for project-skipping [info] Setting p
Roperty:classpath.resource.loader.class => ' Org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader '. [INFO]
Setting property:velocimacro.messages.on => ' false '. [INFO]
Setting property:resource.loader => ' classpath '. [INFO]
Setting property:resource.manager.logwhenfound => ' false '. [INFO]
[Archetype:create-from-project] [INFO] Setting default archetype ' s GroupId:com.company [info] Setting default archetype ' s Artifactid:project [info] Setting def Ault archetype ' s version:1.0-snapshot [INFO]Setting default GroupId:com.company [info] Setting default Artifactid:project [info] Setting default VERSION:1.0-SNAPSH OT [INFO] Setting default Package:com.company.project [info] archetype created in Target/generated-sources/archetype [in FO]------------------------------------------------------------------------[INFO] Build successful [info]-------- ----------------------------------------------------------------[INFO] total time:4 seconds [info] finished At:fri Feb 21:49:52 GMT 2008 [INFO] Final memory:10m/26m [INFO]----------------------------------------------------------- -------------
The following files are found in the target directory of the project:
---target
---generated-sources
---archetype
---our project
Access to the Archetype directory, which is the root of our project to execute:
$ cd target/generated-sources/archetype/$ mvn install [INFO] scanning for projects ... [INFO]------------------------------------------------------------------------[INFO] building project [INFO] Task-segment: [Install] [INFO]------------------------------------------------------------------------[INFO] [
Resources:resources] [INFO] Using default encoding to copy filtered. [INFO]
[Resources:testresources] [INFO]
Using default encoding to copy filtered. [INFO] Setting Property:classpath.resource.loader.class => '
Org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader '. [INFO]
Setting property:velocimacro.messages.on => ' false '. [INFO]
Setting property:resource.loader => ' classpath '. [INFO]
Setting property:resource.manager.logwhenfound => ' false '. [INFO]
[Archetype:jar] [INFO]
[Archetype:add-archetype-metadata] [INFO]
[Archetype:integration-test] [INFO]
[Install:install] [INFO] Installing/home/local/rafale/projects/tmp/project/target/geneRated-sources/archetype/target/project-1.0-snapshot.jar to/home/rafale/.m2/repository/com/company/project/1.0- Snapshot/project-1.0-snapshot.jar [INFO] [archetype:update-local-catalog] [info]--------------------------------- ---------------------------------------[INFO] Build successful [info]-------------------------------------------- ----------------------------[INFO] total time:10 seconds [info] finished At:fri Feb 21:51:57 GMT 2008 [INFO] Final M emory:14m/35m [INFO]------------------------------------------------------------------------
Now our Maven skeleton has been built.
Execute the Mvn:archetype:crawl command, the third important command:
We will find the archetype-catalog.xml skeleton configuration file generated at the root of our local warehouse. View the contents of this file as follows:
<archetype>
<groupId>com.lgy.archetype-demo</groupId>
<artifactId> archetype-demo-archetype</artifactid>
<version>1.0.0-RELEASE</version>
< Description>archetype-demo</description>
</archetype>
By referencing the skeleton file and selecting the skeleton in Eclipse, you can find that the project is created with our skeleton project template.
* When using the archetype:generate command to create the MAVEN skeleton project, we found that sometimes there are too many skeletons, we can use the filter over LV, reference maven this command parameter:
For example:
mvn archetype:generate-darchetypecatelog=local Local
MVN archetype:generate-darchetypecatelog=romote Remote
MVN archetype:generate-darchetypecatelog=http:localhost:8080/archetype-catalog.xml Remote
Reference https://maven.apache.org/archetype/maven-archetype-plugin/usage.html Maven website