Introduction to Maven
Maven, a Java project management tool for building projects, dependency management, and project information management.
Is the Apache organization's open source project.
Maven's core functionality is a building tool with cross-platform features that help us automate to building and provide a complete set of optimized lifecycle models and the basic components / plugins needed to build the task.
Maven also is a dependency on management tools and project information management tools so that developers can better manage dependencies and avoid project information and other issues.
Maven also provides a set of standard rules to reduce the differences between different projects.
Maven standard rules
Maven is a "promise better than configuration" tool, as long as the compliance with Maven's rules, then only a small amount of configuration, Maven will be able to help you complete most of the work you need.
Maven unifies the stage of project construction, providing a standardized build phase model:
1. validate : Verify the correctness of all necessary information for the project
2. initialize : Initialize the build state, such as setting properties or creating a directory
3. generate-sources,process-sources : process the project source file
4. generate-resources,process-resources : process the resource file and copy it to the target directory, waiting for the package
5. compile,process-classes : compile the project's main code to the destination folder
6. generate-test-sources,process-test-sources : process the project test source file
7. generate-test-resources,process-test-resources : process the project to test the resource file and copy it to the target directory
8. test-compile,process-test-classes : compile the project's test source code to the destination folder
9. test : use the project-defined unit test framework for testing
10. prepare-package,package : package the compiled main code into the required format "package"
11. pre-integration-test,integration-test,post-integration-test : if necessary, deploy the packaged "package" into an environment where you can run an integrated test
12. verify : run the defined check step to verify that the "package" is valid or whether it meets the quality criteria
13. install : install the "package" into the local repository as a dependency on other local projects
14. deploy : publish the "package" to the remote repository for others to use and share the project
Maven dependency management and project information management
With regard to dependency management, in the current era, almost every Java application will have a third-party open source library dependency, if use the manual management will seriously affect the efficiency of the developer, and because of increased dependence on the increase in more complex. Fortunately, Maven provides an excellent solution that helps developers better manage projects by introducing elements such as "GroupId", "ArtifactId", "Version", "type", and other elements for Java dependency issues.
On the project information management, when developers use third-party open source library, there will always need to view documents, source code and other needs, before using Maven, developers always need to go to the search engines to find this information, but when the use Maven after these information on the project can be unified in the POM in the statement, to facilitate the search of other people, with the unified management of project information.
POM file is a core content of Maven, which is called "Project Object Model" is the project object model.
It is used to define the basic information of the project, specify how the project to build, declare the project dependency; POM file provides a great advantage of Maven , That is, the project object model can be the greatest degree of independence with the project code, that is, the relationship between the two were decoupled.
Maven coordinate system
Maven components: refers to the usual project after packaging the completion of some of the jar, war and other documents.
Maven's coordinates system orders for various components, and any component must explicitly define its own unique coordinates; a set of Maven coordinates is defined by the following set of elements :
groupId : defines the actual project under which the current Maven project belongs
artifactId : define a Maven module / project in the actual project, recommend using groupId as the artifactId prefix
version : defining the version of the Maven module / project, Maven defines a complete set of version specifications
packaging : define how the Maven module / project is packaged
classifier : help to define some of the ancillary components that correspond to the main component0
Maven repository is based on Maven's coordinate system
Because Maven's coordinate mechanism, any Maven project in the same way to use any "components"; on this basis, Maven can be unified in a certain location to store all Maven project sharing "components", that is, the repository; because the repository, so Maven Items no longer need to store their dependent "components", but in turn only need to declare these dependent coordinates, when needed, Maven will automatically find the warehouse "component" coordinates and use them.
There are two types of repository, local repository and remote repository. When Maven looks for "components" based on coordinates, Maven first looks at the local repository, and if the local repository exists, it is used directly; if the local repository does not exist, Or need to see if there is a newer version, Maven will go to the remote repository to find, when found in the required" components ", will be downloaded to the local repository and then use; if the final local repository and remote repository can not find the the required "component", Maven will be an error.