Maven first experience, can quickly understand the role of Maven and installation methods

Tip: After the article is written, the table of contents can be automatically generated. How to generate it can refer to the help document on the right

1. Why learn Maven?

1. The size of jar is getting bigger and bigger

As we learn more, we will use more and more frameworks, or the degree of framework encapsulation is getting higher and higher, and the jar packages used in the project are also increasing. It is very common to have hundreds of jar packages. If you use Maven to import These jar packages only need to configure a few "dependencies".

Dependency: If A project uses resources such as classes, interfaces, configuration files, etc. of B project, then we can say that A depends on B.

2. The jar package download process is cumbersome

  • The official website of the technology to which this jar package belongs. The official website usually has an English interface, and the structure of the website is different. Even after finding the download link, it is found that it needs to be downloaded through a special tool.

  • Third-party sites provide downloads. The problem is that it is not standardized, and various problems will arise during use.

    • The name of the jar package
    • jar package version
    • The specific details in the jar package
  • After using Maven, the dependent jar package can be automatically downloaded, which is convenient, fast and standardized

3. The dependencies between jar packages are complex

 The dependencies between jar packages are complex, and our manual sorting will undoubtedly increase the extremely high learning cost

With Maven, there is almost no need to manage these relationships, only a few adjustments can be made.

2. Maven download and installation

1. Download address

Maven – Download Apache Maven icon-default.png?t=M85Bhttps://maven.apache.org/download.cgi       You can choose the corresponding Maven program to download according to your needs.

      If you don't know which one to download, you can download this

     

2. Unzip and configure

1. Choose a directory without Chinese and spaces to decompress, for example, I put it directly on the D drive

2. In the decompression directory, we need to focus on the core configuration file of Maven: settings.xml in the conf folder 

ps: The default value of our Mavende local warehouse: user home directory/.m2/repository

3. Configure Alibaba Cloud's mirror warehouse: Maven downloads the jar package to access foreign warehouses by default, and the speed is very slow. Changing to visit the domestic website can make Maven download the jar package faster.

     Step 1: Comment out the original example

<!-- <mirror>
  <id>maven-default-http-blocker</id>
  <mirrorOf>external:http:*</mirrorOf>
  <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
  <url>http://0.0.0.0/</url>
  <blocked>true</blocked>
</mirror> -->

   Step 2: Add new configuration

<mirror>
		<id>nexus-aliyun</id>
		<mirrorOf>central</mirrorOf>
		<name>Nexus aliyun</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

4. Configure the basic JDK version of the Maven project

Reason for configuration: The default JDK version here is 1.5, and the version we are familiar with and commonly used is JDK 1.8

The way to modify the configuration is: copy the entire profile tag to the profiles tag in the settings.xml file.

<profile>
	  <id>jdk-1.8</id>
	  <activation>
		<activeByDefault>true</activeByDefault>
		<jdk>1.8</jdk>
	  </activation>
	  <properties>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
	  </properties>
</profile>

5. Configure MAVEN_HOME

 Also configure PATH

 Generally speaking, it does not need to be configured. It does not rule out that some people cannot use Maven. If necessary, you can configure it.

Guess you like

Origin blog.csdn.net/qq_42176665/article/details/127778592