Lin Bingwen Evankaka original works. Reprint please specify the source Http://blog.csdn.net/evankaka
Abstract: This article is mainly about the use of Maven in the process of some commonly used commands, and patch instructions, and finally the Pom.xml file of some constructs.
One, maven common command 1.1, MAVEN parameters
- D Incoming Property parameter
-P Use the configuration specified in the POM
-e Displays information about MAVEN running errors
-O execute command offline, i.e. do not go to Remote Repository update package
-X Displays the debug information that Maven allows
-U force to Remote reference Update snapshot package
For example MVN install-dmaven.test.skip=true-poracle
Additional parameters can be obtained by MVN help
1.2. Maven Common Command 1, mvn clean
Description: Clean the temporary files produced by the project, usually the target directory under the module
Here's a look at the table of contents:
2. MVN Package
Description: The project packaging tool will generate files such as jar or war in the target directory under the module, such as running results.
The resulting files are as follows:
3, MVN test
Description: Test the command, or execute the test case for JUnit under src/test/java/.
4. MVN Install
Description: The module installation command copies the packaged Jar/war file to your local repository for other modules to skip the test using-dmaven.test.skip=true (and also skips the tests compile)
The first red box is its input path, and the path file for the local repository is as follows:
5. MVN Deploy
Description: The Publish command publishes the packaged files to a remote reference, provides other people with download dependencies, and is generally posted to the company, which I do not configure, so it is not demonstrated.
1.3, Maven-eclipse-plugin plug-in 1, mvn eclipse:eclipse
Description: Generate Eclipse config file, import to eclipse Open, if use m2eclipse plug-in, you can not command. Import directly into eclipse with plugins
Note: Projects that are produced with the secondary command need to configure the M2_home command in eclipse to point to your local warehouse folder.
Take a look at the results of the build:. Classpath is the byte code.
2, MVN Eclipse:m2eclipse
Generate Eclipse configuration file, which depends on m2eclipse in eclipse
-ddownloadsources=true Download the source file of the dependent package
-declipse.addversiontoprojectname=true adding version information to the project name
3, MVN Eclipse:clean
Purge Project files for Eclipse
Look at the contents of the file, no project files
1.4, Maven-jetty-plugin plug-in 1, mvn Jetty:run
Description: You can run the note with the jetty server directly: This command applies only to the war module, the Web module.
2, MVN archetype:generate
Description: module creation command, after executing the command, will be prompted to select the template to create the project, here (Maven-archetype-quickstart)
You will be prompted to enter GroupID (the path where the package is stored):
Eg:com.lin
Prompt for input artifactid (module name):
Eg:test-core
Prompt to enter version (versions):
1.0.0-snapshot
Prompt for package (refers to the basic packet path in the project):
Eg:com.lin
Prompt confirmation, enter can be
1.5, Maven-release-plugin plug-in Description: Release version, can be integrated with SCM tools to provide version management. Not equivalent to version control. The goal is required to be allowed. Two commonly used goal are as follows:
1, MVN Release:clean
Cleaning up the release operation is a legacy file
2, MVN Release:branch
Description: Creates a branch that creates a branch path that executes under a branch
Name in the-dbranchname=xxxx-100317 branch
-dupdatebranchversions=false whether to update the version information for the branch, false by default
-dupdateworkingcopyversions=false whether to update the skeleton's version information, by default True
3, MVN Release:prepare
Create the tag, there will be interactive process, the tag in the version of the Pom and the trunk of the new version number, each module will ask, the default is the minimum version number +1
-dtag = 4.4.0 will create the name folder in tags
-ddryrun=true Check that the settings are correct and can be used for testing, resulting in some modified configuration file information.
Command:
MVN Release:perform
The command will automatically check out the tag we just made and then package it and distribute it to the remote Maven repository.
1.6. Maven Site Report
1, MVN project-info-reports:dependencies
Build a report that the project depends on
2, MVN dependency:resolve
View Dependencies
View project Dependencies
3, MVN Dependency:tree
Print out the entire dependency tree of the project
4, MVN Dependency:analyze
Help you analyze dependencies to remove useless, repetitive dependencies of good helpers
5, MVN Install-x
Track the full trajectory of dependencies
6. Life cycle
Resource->compile->process-classes->process-test-resources->test-compile->test-> Prepare-package->package
Resources:resources binding in the resource processing phase, used to copy files under Src/main/resources or any other directory specified in the output directory
Resources:testresources Copy the Resources directory under test or any other specified directory to the test output directory
Compiler:testcompile to compile the test class (including the copy resource file)
Surefire:test Running test Cases
Jar:jar hit Jar bag
Ii. various scopes
Compile (compilation scope)
Compile is the default scope, and if a scope is not provided, the scope of the dependency is the compilation scope. Compilation scope dependencies are available in all classpath, and they are also packaged.
Provided (range provided)
Provided dependencies are only used when the JDK or a container has provided the dependency. For example, if you develop a Web application, you might need the Servlet API available in the compilation Classpath to compile a servlet, but you do not want to include the Servlet API in the packaged war, the Servlet API The jar is provided by your application server or the servlet container. A dependency that has been provided for scope is available at compile classpath (not at runtime). They are not transitive and will not be packaged.
Runtime (Runtime Range)
Runtime relies on the need to run and test the system, but it is not required at compile time. For example, you might only need the JDBC API JAR when compiling, and only the JDBC driver implementation is required when running.
Test (Testing range)
Test range dependencies are not required for general compilation and runtime, and they are available only during the test compilation and test run phases.
System (systems-wide)
System-wide dependencies are similar to provided, but you must explicitly provide a path to the jar file in the local system. This is done to allow compilation based on local objects, which are part of the System class library. Such artifacts should always be available, and MAVEN will not look for it in the warehouse. If you set a dependency scope to a system scope, you must provide a SYSTEMPATH element at the same time. Note that this range is deprecated (you should always try to reference dependencies from a public or custom Maven repository).
Three, the Pom file explanation Pom Full name is the project object model, that is, the item objects. Pom.xml is MAVEN's project description file, which resembles the Project.xml file with Antx. The Pom.xml file describes the project's information in XML, including the project name, version, project ID, project dependencies, compilation environment, continuous integration, project team, contribution management, generating reports, and so on. In summary, it contains all the project information.
3.2.1. Basic configuration of Pom.xml
<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/xsd/maven-4.0.0.xsd" > < modelversion>4.0.0</modelversion> <groupId>com.lin.learning</groupId> < artifactid>maven-hellowrold</artifactid> <version>0.0.1-SNAPSHOT</version> < packaging>jar</packaging> <name>maven-hellowrold</name> <url>http:// maven.apache.org</url> <properties> <project.build.sourceencoding>utf-8</ Project.build.sourceencoding> </properties></project>
Modelversion describes which version of the project descriptor the Pom file is to follow.
GroupId a universally unique identifier for a project. Usually the name of a completely correct package is used to distinguish it from other items (for example: Org.apache.maven).
Artifactid The identifier specified for artifact within a given GroupID group is unique, and artifact represents the component (output) that was made or applied by a project.
Version the current project produces artifact versions above 4 elements integral, where groupid, Artifactid, and version describe the dependent project unique flag.
1. pom.xml File structure
<project><modelversion>4.0.0</modelversion><!-The basic information of the Basics project-><groupid>...< /groupid><artifactid>...</artifactid><version>...</version><packaging>...< /packaging><dependencies>...</dependencies><parent>...</parent>< Dependencymanagement>...</dependencymanagement><modules>...</modules><properties> </properties><!-build Settings Project compilation Settings-><build>...</build><reporting>...</ reporting><!-More project information information-><name>...</name><description>...</ description><url>...</url><inceptionyear>...</inceptionyear><licenses>...< /licenses><organization>...</organization><developers>...</developers>< contributors>...</contributors><!--Environment Settings-><issuemanagement>...</ issuemanagement><cimanagement≫...</cimanagement><mailinglists>...</mailinglists> <scm>...</scm>< Prerequisites>...</prerequisites><repositories>...</repositories><pluginrepositories >...</pluginrepositories><distributionmanagement>...</distributionmanagement><profiles >...</profiles></project>
Project is the root node of pom.xml and for other elements refer to Pom Reference
2. Pom is an important 3 relationship Pom has 3 important relationships: dependency, inheritance, composition.
2.1. Dependency relationship
<dependencies><dependency><groupid>junit</groupid><artifactid>junit</ Artifactid><version>4.0</version><type>jar</type><scope>test</scope> <optional>true</optional></dependency>...</dependencies>
If you want to rely on a jar package that is not in a MAVEN library, the simple way to do this is to install the jar package to the local MAVEN library using the following command:
MVN install:install-file-dfile=my.jar-dgroupid=mygroup-dartifactid=myartifactid-dversion=1
Then add the dependency.
2.2. Inheritance Relationship
Another powerful change that MAVEN brings is Project inheritance.
2.2.1. Defining a parent Project
<project><modelversion>4.0.0</modelversion><groupid>com.mygroup </groupId>< Artifactid>my-parent</artifactid><version>2.0</version><packaging>pom</packaging ></project>
The packaging type, defined as POM, is used to define multiple items as parent and composite. Of course the Pom of the MAVEN project we created inherits Maven's Super Pom, and if you want to see the full POM structure of the project (parent or child), you can run:
MVN Help:effective-pom
You can do it.
2.2.2. Sub-project configuration
<project><modelversion>4.0.0</modelversion><groupid>com.mygroup </groupId>< Artifactid>my-child-project</artifactid><parent><groupid>com.mygroup </groupId>< Artifactid>my-parent</artifactid><version>2.0</version><relativepath>, .... /my-parent</relativepath></parent></project>
2.3. Synthetic relationships
A project has multiple modules, also called multiple modules, or synthetic projects. The definition is as follows:
<project><modelversion>4.0.0</modelversion><groupid>com.mygroup </groupId>< Artifactid>my-parent</artifactid><version>2.0</version><modules><module> My-child-project1<module><module>my-child-project2<module></modules></project>
Where module describes the relative path of the subproject.
2.4. Dependencymanagement and Profile
Maven also provides a dependencymanagement element to provide a way to unify dependent version numbers. The dependencymanagement element is typically used on the top-level parent POM. Using the Dependencymanagement element in Pom.xml allows you to reference a dependency in a subproject without explicitly listing the version number. Maven walks up the parent-child hierarchy until a project with the dependencymanagement element is found, and then it uses the version number specified in the Dependencymanagement element, which solves the problem of modifying the incomplete dependent version number.
Maven's profile element can customize a particular build for a particular environment, making portability possible between different environments. For example, to use production profile to run MVN install, you need to pass in the-pproduction parameter at the command line, where production is the profile ID. To verify that the production profile overrides the default compiler plug-in configuration, you can run Maven like this by turning on debug input (-X).
Copyright NOTICE: This article for Bo Master Lin Bingwen Evankaka original article, without Bo Master permission not reproduced.
Maven common command Daquan and pom file explanation