Teach you how to build a Maven environment in idea

One: Introduction to Maven

1. What is Maven?

Maven is a project management tool, it includes a project object model (Project Object
Model), a set of standards, a project life cycle (Project Lifecycle), a dependency management system (Dependency
Management
System), and used to run the definition in The logic of the plugin's goal in the phase of the life cycle. When you use Maven, you use a clearly defined project object model to describe your project, and then Maven can apply cross-cutting logic that comes from a set of shared (or custom) plugins.

At present, we are using Maven to build the project environment, because the ordinary environment requires us to import a series of jar packages, and Maven can help us save these operations. By adding some code and then Maven will automatically prepare the environment for you.
2. The comparison between the self-configured maven environment and the built-in maven environment in idea.

In general, using the built-in maven can save the tedious configuration process and can be used immediately, but in addition, there are still more disadvantages; on the contrary, configuring maven by yourself will appear to be more free and convenient to use.
The benefits of configuring maven by
yourself : 1. If you are a novice, it is recommended to configure maven by yourself, which will help you learn and understand maven better. After all, IDE will block many details, which is not conducive to novice learning.
2. Idea's own maven is in its own path and configuration. In order to avoid inexplicable problems when upgrading (whether upgrading idea or wanting to upgrade maven), custom configuration can reduce errors.
3. Do not rely on IDEA, you can also develop on other IDEs. If you happen to use eclipse at the same time, it will be better to manage independently, you can share the configuration and warehouse between the two environments.
4. Idea's own maven configuration file and warehouse are in the C drive, and generally don't put anything on the C drive. Configure maven by yourself. Not only can you freely manage the location of the configuration file and warehouse, but you can also change the maven version at will.

Two: Maven environment construction

1. Download the Maven
official website from the official website : https://maven.apache.org/ After the
Insert picture description here
download is complete, unzip it.
2. Configure environment variables Configure the following variables
in the computer's system environment
variables:

  • The bin directory under the M2_HOME maven directory
  • MAVEN_HOME maven's directory
  • Configure %MAVEN_HOME%\bin in the system path

Signs of successful configuration of environment variables:
Insert picture description here
3. Configure Alibaba Cloud Mirror
Function: Make the download faster
. Add the following configuration to conf/settings.xml under the maven folder

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

4. Create a Maven local warehouse
Create a new folder in the Maven directory.
Also add the following configuration in conf/settings.xml.

 <localRepository>E:\maven\apache-maven-3.6.3\maven-repo</localRepository>

5. Use Maven in IDEA
1. Start idea
2. Create a MavenWeb project
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
3. Wait for the project to be initialized
Insert picture description here
Insert picture description here
4. At this time there will be a lot of things
Insert picture description here
in the Maven warehouse 5. Maven settings in
IDEA Note: After the IDEA project is created successfully, Take a look at the Maven configuration.
Insert picture description here
Insert picture description here
6. At this point, the configuration and use of Maven in IDEA is OK.
7. Create a normal Maven project.
Insert picture description here
Insert picture description here
Insert picture description here
8. Configure Tomcat in IDEA
Insert picture description here
Insert picture description here
Insert picture description here
9. Running effect
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_44867340/article/details/113819985