Java project construction management Maven installation and configuration

1. Download and install

First install and configure jdk [Guide the way: jdk installation and configuration] , and then download and install maven (most use maven3, version 3.xx, you can go to the official website to download https://maven.apache.org/download.cgi , Generally download bin.zip version, Linux system download .gz)
Pay attention to the installation location, here is the installation in the D:\Program\Mavendirectory as an example.

2. Configure environment variables

Windows computer as an example:
My computer-right click-properties-advanced system settings-environment variables
New system variable: variable name MAVEN_HOME, variable value D:\Program\Maven
Edit user variable: variable name Path, new variable value D:\Program\Maven\bin
(user variable must go to the bin folder, some large The guy said that user variables are splicing system variables, for example Path = %MAVEN_HOME%\bin, but sometimes it doesn’t work if I use this way, so I am used to spelling the complete address directly, as long as it can be matched)

3. Create a local maven warehouse address

Just create an empty folder yourself, as long as the configuration path is correct. Here is an example of a local warehouse created in D:\Repositories\Maven.

Maven detect whether the installation was successful:
directly in the cmd in run mvn -versionon the line, the normal print run is successful.

4. Modify the configuration file of the warehouse storage location

In the D:\Program\Maven\conf\settings.xmlconfiguration inside, maven has a default warehouse storage folder locally, adding the warehouse location created by yourself.
Default location:

<!-- localRepository  
 | The path to the local repository maven will use to store artifacts.  
 | C: ${user.home}/.m2/repository  
 | <localRepository>/path/to/local/repo</localRepository>
-->

Add your own local warehouse at the back

<localRepository>D:/Repositories/Maven</localRepository>

Note the forward and backward slashes

5. Configure the maven plugin in the development environment

The development environment here takes IntelliJ IDEA 2019.2.3 as an example. Note that after configuration here, it is only for a certain project, not all projects under idea.
File - Settings - Build Execution Deployment - Build Tools - under Maven:
Maven home directoryTo select the directory you installed maven job is some direct Bundled (Maven 3) is also possible, consistent line
User setting filemodified to D:\Program\Maven\conf\settings.xml
Local repositorybe modified to D:\Repositories\Maven
be checked overridebefore they can be modified.

6. Attention

Configure the mirror in settings.xml, because all jar packages need to be fetched from the central warehouse of maven. However, the URL of the central warehouse is foreign and the download speed is very slow. We generally configure it as an Alibaba Cloud mirror.

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

In this way, the entire complete project build configuration of maven is completed.

Guiding the way: maven build java web project

Guess you like

Origin blog.csdn.net/Mrlujiao_code/article/details/113104942