I have heard of Maven for a long time. At that time, I knew it was a project management tool used to manage jar packages. I knew it was superficial. After reading the video this time, I learned a little and understood it more deeply. Let's take a look at the basic Maven knowledge.
Maven is a tool under the Apache Foundation for project management. Maven is based on the project Object Model (
Pom), you can use a short description to manage software project management tools for project building, reporting, and documentation.
SVN should be familiar to everyone. It is a version management tool that manages the timeline of a project, from 1.0 ...... 2.0, 2.1 ...... It can be seen as vertical management, but projects in SVN are mutually independent. That is to say, SVN is difficult to manage changes between projects. For example, a large company usually has many projects, Jar packages between projects are repeated, and projects may have a common part, such as permission control, some functional modules of the project may be used in this project. This is very difficult for SVN. Maven appears to solve this problem. My understanding: Maven is a tool built on multiple projects to maintain the common parts of multiple projects (such as common jar packages, common modules (actually self-developed jar packages) and dependencies (relationships between projects) are managed horizontally. The two are complementary to SVN. They are used together to manage multiple projects, so that each project grows in an orderly manner and communicates with each other from where else. Let's see, just like we humans, we need to grow older and expand interpersonal relationships. Let's take a look at the simple installation and use of Maven.
1. Install Maven:
1. Prerequisites: JDK is installed and environment variables are configured;
2, download and install: to the official website: http://maven.apache.org/download.cgi Maven download, download and unzip to complete (preferably in the English directory ).
3. Configuration:
1), environment variable: As with the JDK environment variable configuration, add maven_home = D: \ Maven \ apache-maven-3.1.1 in the user variable, and then modify the path, add % maven_home % \ bin; to the configuration. Input MVN-version in the running window. The Maven version is displayed, indicating that the version has been installed.
2) local repository Configuration:
By default, Maven creates. m2 in the root directory as the local repository. Here we need to modify the setting. xml file under conf (Maven configuration must be configured here) and set the path of the local repository:
<!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ~/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <localRepository>D:/maven/repo</localRepository>
In this way, the local repository is set to D:/Maven/Repo, And the downloaded jar package is inside. Of course, we can also set a central repository in this configuration file (that is, Apache provides a remote repository, covering almost all commonly used jar packages), private servers, and so on. There are examples of annotations in this file. Let's take a look at English.
For example, if you configure the Nexus private server as an image, all dependencies will be found here:
2. Create a Maven project:
1. Configure Maven in eclipse. You need to configure the root path and the setting file. See the two figures:
Then you can create a Maven project. Notes:
1. project coordinates:
Groupid: used to indicate the project name;
Artifactid: used to indicate the module name of the project. We recommend that you use the project name-Module name;
Version: version number of the project.
2. Create a project structure:
The source code should be placed in src/main/Java.
The source code resource file should be placed in the src/main/resources folder.
The test code should be placed in src/test/Java.
The resource file of the test code should be placed in the src/test/resources folder.
3, Pom. xml file simple writing, here mainly write reference jar package, and dependencies between other projects, jar package dependency GVA can go to the http://mvnrepository.com Query
4. At last, let's take a look at several common commands in the maven project:
MVN clean --> indicates to run the clean operation (the data in the target folder will be cleaned by default)
MVN clean compile --> indicates to run the cleanup command first and then compile the code, and then compile the code into the target folder.
MVN clean test --> Run clean and Test
MVN clean package --> RUN cleanup and Package
MVN clean install --> Run clean and install. The prepared package is installed in the local repository so that other projects can call
MVN clean deploy --> Run clean and publish (publish to private server)
This is the local installation of Maven and the simple use of the project. However, in the project, we also need the Nexus private server for local management of the project, so as to facilitate the absence of the network, and to get rid of the dependency on the central repository. Next blog will introduce it. Maven learning, need to accumulate in practice, here recommended learning materials: http://juvenshun.iteye.com/
Maven preliminary Learning