http://blog.csdn.net/kakashi8841/article/details/17427043
Before reading this article please make sure that you successfully installed MAVEN, if you have not successfully installed, please look first: Maven primer (1)-Install here the article installed successfully before continuing.
Because maven may download dependent files from the central database while executing some plug-in targets, stay connected when using MAVEN.
Now if you can't wait, try typing in the command-line terminal first:
[Plain]View Plaincopy
- MVN clean Install
This will print the various files that are being downloaded. Does it feel good? OK, let's get to the bottom of this:
1. Create a MAVEN project first.
The terminal input command is then executed:
[Plain]View Plaincopy
- MVN archetype:generate-dgroupid=com.mycompany.app-dartifactid=my-app-darchetypeartifactid= Maven-archetype-quickstart-dinteractivemode=false
As before, it is also constantly downloading all the necessary files.
By the end of the command, you find that there is a directory in the current directory called My-app, which contains the pom.xml and SRC directories, such as:
The full directory structure is as follows:
Isn't it amazing?
Magic to Magic, just that command so complex, what does it mean, what is the operation? Don't worry, we'll take a slow look.
First, you have just executed a maven target of "archetype:generate" and passed different parameters to that target. "Archetype" is a plugin that contains the goal of "generate". If you are familiar with ant, you can assume that it is a task in ant. This goal creates a simple project based on a prototype. In short, a plug-in is a collection of common goals. Jboss-maven-plugin, for example, is used to handle a variety of different jboss projects.
Next, let's take a look at the properties of-dgroupid-dartifactid-darchetypeartifactid-dinteractivemode
They are actually parameters of Java execution.
GroupId: Generally filled with the project name, some people like to fill in the company name. Here, a company generally has a number of projects, if the company name is filled here, then Artifactid can only fill in the project name. And version is undoubtedly the revision number. This makes the granularity of the project more coarse. Therefore, I generally groupid is to fill in the project. For example: Com.taobao.shop.
Artifactid: Fill in the above items, then you can fill in the module here. For example: Login
Version: This module is filled in here.
OK above the GroupID, Artifactid, version (abbreviated GAV) constitutes the "positioning System" in Maven, theoretically all the dependencies can be found through Gav.
Let's look at the other parameters,
Archetypeartifactid: This parameter is actually specifying a template to initialize your project. For example, you are a normal Java application, or a Web program, there is a corresponding template.
If you still don't know how to build a Maven project, you can also use the command line:
MVN Help:describe-dplugin=archetype
, here help is also a plug-in, then describe is the target, and the-dplugin parameter indicates describe to see the archetype plugin information.
This will get the help of archetype this plugin.
Name:maven archetype Plugin
Description:maven archetype is a set of tools to deal with archetypes, i.e.
An abstract representation of a kind of project that can is instantiated into
A concrete customized Maven project. An archetype knows which files would be
Part of the instantiated project and which properties to fill to properly
Customize the project.
Group Id:org.apache.maven.plugins
Artifact Id:maven-archetype-plugin
version:2.2
Goal Prefix:archetype
This plugin has 8 goals:
Archetype:crawl
Description:crawl a Maven Repository (filesystem, not HTTP) and creates a
Catalog file.
Archetype:create
Description:the archetype creation goal looks for an archetype with a
Given GroupId, Artifactid, and version and retrieves it from the remote
Repository. Once the archetype is retrieved, it's then processed against a
Set of user parameters to create a working Maven project.
Deprecated. Please use the Generate Mojo instead.
Archetype:create-from-project
Description:creates an archetype project from the current project.
This goal reads your source and resource files, the values of their
Parameters, and properties specify in A. Property file, and uses them
To create a Maven archetype project using the Maven-archetype packaging. If
You build the resulting project, it'll create the archetype. You can then
Use this archetype to create new projects that resemble the original.
The Maven-archetype-plugin uses Velocity to expand template files, and this
Documentation talks about ' Velocity Properties ', which is values
Substituted into Velocity templates. See the Velocity User's Guide for more
Information.
This goal modifies, the text of the files of the current project to form the
Velocity template files, the make up the archetype.
GAV
The GAV values for the current project is replaced by properties:
GroupId, Artifactid, and version. The user chooses new values for these
When generating a project from the archetype.
Package
All the files under one specified Java (or cognate) is relocated
To a project, the user chooses when generating a project. References
To the class name is replaced by a property reference. For example, if
The current project ' s sources is in the
Org.apache.saltedpeanuts, then any example of the string
Org.apache.saltedpeanuts is replaced with the Velocity property reference
${packagename}. When the user generates a project, this is in turn
Replaced by he or her choice of a package.
Custom properties
Identify additional strings that should being replaced by
Parameters. To add custom properties, your must use the Propertyfile
parameter to specify a property file. See the documentation for
Propertyfile for the details.
Note that need to edit the results of this goal. This goal has no
Exclude unwanted files, or add copyright notices to the Velocity
Templates, or add more complex elements to the archetype metadata file.
This goal also generates a simple integration-test that exercises the
Generated archetype.
Archetype:generate
Description:generates a new project from an archetype, or updated the
Actual project if using a partial archetype. If the project is fully
Generated, it is generated in a directory corresponding to its artifactid.
If the project is updated with a partial archetype, it's done in the
Current directory.
Archetype:help
Description:display Help information on Maven-archetype-plugin.
Call
MVN archetype:help-ddetail=true-dgoal=<goal-name>
To display parameter details.
Archetype:integration-test
Description:execute the Archetype integration tests, consisting in
Generating projects from the current archetype and optionally comparing
Generated projects with reference copy.
Each IT consists of a sub-directory in src/test/resources/projects
Containing:
-a goal.txt file, containing a list of goals to run against the generated
Project (can be empty, content ignored before Maven-archetype-plugin
2.1),
-an archetype.properties file, containing properties for project
Generation
-An optional reference/directory containing a reference copy of the
Expected project created from the IT.
Notice that it's expected to being run as part as of a build after the
Package phase and is directly as a goal from CLI.
Archetype:jar
Description:build a JAR from the current archetype project.
Archetype:update-local-catalog
Description:updates the Local Catalog
For more information, run ' mvn help:describe [...]-ddetail '
[INFO]------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO]------------------------------------------------------------------------
[INFO] Total time:3.851s
[INFO] Finished At:tue Dec 02:45:02 CST 2013
[INFO] Final memory:11m/156m
[INFO]------------------------------------------------------------------------
We note that the archetype plugin itself has a help target and seems to be able to find more helpful information.
Then we can try to use the following command to find information about the Generate target:
MVN archetype:help-ddetail=true-dgoal=generate
Then, the content returned is:
cmatomacbook-pro:~ cjunhong$ mvn archetype:help-ddetail=true-dgoal=generate
[INFO] Scanning for projects ...
[INFO]
[INFO]------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO]------------------------------------------------------------------------
[INFO]
[INFO]---maven-archetype-plugin:2.2:help (default-cli) @ standalone-pom---
[INFO] org.apache.maven.plugins:maven-archetype-plugin:2.2
Maven archetype Plugin
Maven archetype is a set of tools to deal with archetypes, i.e. an abstract
Representation of a kind of project that can is instantiated into a concrete
Customized Maven project. An archetype knows which files would be part of the
Instantiated project and which properties to fill to properly customize the
Project.
Archetype:generate
Generates a new project from an archetype, or updated the actual project if
Using a partial archetype. If The project is a fully generated, it is generated
In a directory corresponding to its artifactid. If the project is updated with
A partial archetype, it is done in the current directory.
Available Parameters:
Archetypeartifactid
The archetype ' s artifactid.
Expression: ${archetypeartifactid}
Archetypecatalog (default:remote,local)
The archetype catalogs to use to build a list and let the user choose
From. It is a comma separated list of catalogs. Catalogs use following
Schemes:
-' file://... ' with archetype-catalog.xml automatically appended when
Pointing to a directory
-' http://' https://... ' with archetype-catalog.xml always appended
-' local ' which is the shortcut for ' File://~/.m2/archetype-catalog.xml '
-' remote ' which is the shortcut for Maven Central repository, ie
' Http://repo1.maven.org/maven2 '
-' internal ' which is an internal catalog
Since 2.0-alpha-5, default value is no longer internal,local but
Remote,local. If Maven Central Repository catalog file is empty, internal
Catalog is used instead.
Expression: ${archetypecatalog}
Archetypegroupid
The archetype ' s groupId.
Expression: ${archetypegroupid}
Archetyperepository
The archetype ' s repository.
Expression: ${archetyperepository}
Archetypeversion
The archetype ' s version.
Expression: ${archetypeversion}
Basedir
(No description available)
Expression: ${basedir}
Filter
Applying some filter on displayed archetypes List:format is Artifactid or
Groupid:artifactid.
-Org.apache: Displays all archetypes which contain org.apache in
GroupId
-: Jee or jee-Displays all archetypes which contain Jee in Artifactid
-Org.apache:jee-Displays all archetypes which contain org.apache in
GroupId and Jee in Artifactid
Expression: ${filter}
Goals
Additional goals to immediately run in the project created from the
Archetype.
Expression: ${goals}
Interactivemode (Default: ${settings.interactivemode})
User settings use to check the Interactivemode.
Required:yes
Expression: ${interactivemode}
[INFO]------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO]------------------------------------------------------------------------
[INFO] Total time:1.088s
[INFO] Finished At:tue Dec 02:56:42 CST 2013
[INFO] Final memory:9m/156m
[INFO]------------------------------------------------------------------------
See no, even we just did not explain the interactivemode parameters, it also has a description.
So, be good at using the Help plugin to find the information of a plug-in, and then if you know that the plugin has help target to find more details, then better!
Getting Started with Maven (2)--Creating a MAVEN project