This is the 13th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021
Maven
Introduction to the
Maven is an open source project in the Apaache organization. It mainly serves project management, dependency management and information management based on the Java platform.
Why you need to learnMaven
- in
Javaweb
Development, need to use a large number ofjar
Package, we need to manually import - We need an auto to import and configure this for us
jar
package
Maven was born!
Maven
features
-
Dependency Management System
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>2.5.6</version> </dependency> Copy the code
- Bag type:
jar
Package orwar
package groupId
: Indicates the actual project – company nameartifactId
: Used to represent one of the actual projectsMaven
Module – Project nameversion
: Indicates the version of the project
- Bag type:
-
Multi-module construction
We can decompose a project into modules.
-
Consistent directory structure
The core idea of Maven is convention over configuration, and a project directory structure is established as the standard Java project structure.
-
Consistent build models and plug-in mechanisms
Maven
Project architecture management tool
Rely onJDK
JDK version 1.8 or later is recommended
Maven
The installation
Download address: maven.apache.org/download.cg…
After the download is completed, decompress the directory without Spaces and Chinese.
Directory Structure description
bin
: This directory containsmvn
Scripts to run that are used to configurejava
Order, stand byclasspath
And the relatedJava
System properties, and executeJava
Command.boot
The file under this directory is a classloader, relative to the defaultjava
Class loaders, which provide richer syntax for easy configuration,maven
With this framework, load your own class librariesconf
This directory contains a very important filesettings.xml
.Maven
Core configuration filelib
: This directory contains allMaven
Required at runtimeJava
Class libraries, ` ` MavenIt is developed in modules itself, and there are some included here
Third party dependencies used by Maven
Configuring environment Variables
M2_HOME
:maven
In the directorybin
directoryMAVEN_HOME
:maven
directoryPath
: in the systempath
In the configuration%MAVEN_HOME%\bin
validation
Verification found problems:
- Restart the computer
- If multiple versions are installed, check to see if any environment variables have been set
Ali Cloud Mirror
Generally, access to the Internet is slow, so we use the domestic mirror warehouse.
- Mirror:
mirrors
- Domestic suggestions to use ali Cloud mirror
Open the Maven configuration file (typically in the Maven installation directory conf/settings.xml for Windows machines) and add a mirror child node to the
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>Ali Cloud public warehouse</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
Copy the code
Configuring a Local Warehouse
Warehouses are generally divided into two types: local and remote.
Establish local warehouse:
Open the Maven configuration file (usually in the Maven installation directory conf/settings.xml for Windows machines) and modify it in
<localRepository>${MAVEN_HOME}/repo</localRepository>
Copy the code
Create the repo folder in the Maven installation directory
inIDEA
The use ofMaven
IDEA has a default Maven configuration and we need to replace Maven with our own
IDEA will help us download the dependency automatically after changing the warehouse.
Maven
Project directory structure
directory | instructions |
---|---|
${basedir} |
storepom.xml And all the subdirectories |
${basedir}/src/main/java |
The projectjava The source code |
${basedir}/src/main/resources |
Resources for the project, such as configuration files |
${basedir}/src/test/java |
The test class for the project |
${basedir}/src/test/resources |
Resources used for testing |