Maven Learning (1): Introduction to Maven

1. What is Maven for?

Maven is a project management and build automation tool. Read the introduction of Maven's official website in detail ( http://maven.apache.org )

Maven provides developers with a complete build lifecycle framework. The development team can automatically complete the basic build configuration of the project in very little time, because Maven uses a standard directory structure and a default build life cycle. Maven makes the developer's job easier when it comes to creating reports, checking, building, and testing auto-configurations .

2. Maven download and installation

maven download URL http://maven.apache.org/download.cgi


Select the latest version to download locally, and then extract the compressed package to the D:\java\apache-maven-3.5.2 directory


Next, you need to configure environment variables, provided that JDK has been configured, this version currently only supports JDK1.7

M2_HOME = D:\java\apache-maven-3.5.2


After configuration, enter cmd and enter: mvn -v 

Then the message prompts congratulations on the successful installation, and the instructions are ok

3. Maven repository

The most direct help that using Maven brings to us is that the jar packages are managed uniformly, so where are these jar packages stored? They are in your  local repository  , in the C:\Users\username.m2 directory (you can also change this default address of course).

In fact, the local warehouse can be understood as "cache", because the project will first obtain the jar package from the local warehouse. When the specified jar package cannot be obtained, the local warehouse will download the jar package from the  remote * warehouse (or central warehouse)*, and put into a local repo for future use. This remote repository is officially provided by Maven and can be accessed through  http://search.maven.org/  . In this way, the local repository will grow larger and larger as the project accumulates.

3.1 Modify the local warehouse configuration

Enter the conf subdirectory under the Maven installation directory and open settings.xml to modify the configuration

Maven's default local warehouse location is ".m2/repository" in the current user's working directory. During use, there will be more files in this directory, and the space will be larger and larger. It is generally recommended to change to another disk directory. The following configuration changes the default local repository to the D:\m2_repository directory (this directory structure needs to be created by yourself).

<localRepository>D:\m2_repository</localRepository>

3.2 Modify the address of the central warehouse

The files in Maven's default central repository are incomplete. Therefore, you need to add other mirror addresses by yourself. Add the following to the "<mirrors>" tag in the settings.xml file:

<mirror>

       <id>ibiblio</id>

       <mirrorOf>central</mirrorOf>

       <name>Human Readable Name for this Mirror.</name>

       <url>http://mirrors.ibiblio.org/maven2/</url>

     </mirror>

Save the changes made, and you also need to copy the settings.xml file to the "D:\m2_repository" directory.

Of course, it is also possible if you do not modify the central warehouse.

Maven central warehouse address summary:

1. http://www.sonatype.org/nexus/ private server nexus tool use
2. http://mvnrepository.com/ (recommended)

3、http://repo1.maven.org/maven2

4. http://maven.aliyun.com/nexus/content/groups/public/ Alibaba Cloud (strongly recommended)

5. http://repo2.maven.org/maven2/ private server nexus tool use

6、http://uk.maven.org/maven2/

7、http://repository.jboss.org/nexus/content/groups/public

8. http://maven.oschina.net/content/groups/public/ oschina is a pity, I have been using this before, but now I have Alibaba Cloud to wipe my ass

9、http://mirrors.ibiblio.org/maven2/

10、http://maven.antelink.com/content/repositories/central/

11、http://nexus.openkoala.org/nexus/content/groups/Koala-release/

12、http://maven.tmatesoft.com/content/groups/public/

The address of the above central warehouse is reproduced https://blog.csdn.net/qq_23689053/article/details/79232784

4. Maven common commands

  • mvn clean : empty the output directory (ie the target directory)

  • mvn compile : compile source code

  • mvn package : Generate component packages (usually jar packages or war packages)

  • mvn install : install the artifact package to the local repository

  • mvn deploy : deploy the artifact package to the remote repository



Reprinted:

http://blog.csdn.net/quuqu/article/details/52458589


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324609878&siteId=291194637