Maven is a
基于项目对象模型(POM)用于进行项目的依赖管理、生命周期管理
tool software with
core functions:
- Depend on jar package management
- Project life cycle management
- Polymer engineering
Installation configuration
Maven is developed based on Java language and therefore relies on JDK (JDK1.7+ recommended)
-
Download maven: official website , Baidu network disk
-
No installation required, unzip, ready to use out of the box
Directory structure:- bin stores instruction files (Maven provides an mvn instruction)
- boot contains a jar file of a class loading framework
- conf contains Maven’s core configuration file settings.xml
- lib stores the jar files required for maven to run
-
Configure environment variables
Project structure
project (project name)
– src
– main (storing the source files of the project)
– java (storing java code, equivalent to the src directory in traditional projects)
– resources (storing configuration files and static resource logs, equivalent to transferring projects web directory)
– test (storage the unit test code of the project)
– pom.xml
Project dependency management
process
- Configure dependencies in pom.xmI in the project
- maven reads the pom.xml of the project
- Maven checks whether the local warehouse has the jars required by the project, and if so, it is directly introduced into the project.
- If the local warehouse does not have the dependencies required by the project, maven will connect to the remote warehouse to download (grid)
- Maven first saves the jar file downloaded from the remote warehouse to the local warehouse, and then references it from the local warehouse to the project.
Warehouse introduction
本地仓库
: It is a folder on the local computer (can be any customized folder)远程仓库
中央仓库
: The official warehouse provided by maven, including all required dependencies (no configuration required)公共仓库
: Third-party warehouses other than the central warehouse are public warehouses, such as aliyun (configuration required)私服
: Maven warehouse built by the enterprise for internal use
Maven warehouse configuration
/conf/settings.xml
Configure in
- Configure local warehouse
<localRepository>D:\software\install\apache-maven-3.8.1\repo</localRepository>
- Configure public repository
<mirrors> <mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror> </mirrors>
- Configure private server
private server
The company builds a Mawen warehouse for internal use
- Developers need to rely on downloading directly from private servers
- Private servers can realize the sharing of internal dependencies within the enterprise: when an enterprise develops a common plug-in (jar), it can be published to the private server, and other developers who can connect to the current private server can share this plug-in.
Private server construction
We can build private servers through the specialized Maven warehouse management software. For example: Apache Archiva, Nexus
- Download Nexus: Baidu Cloud Disk
- Unzip Nexus
- Install and run
- Enter
nexus-2.14.5-02/bin
directory - Open the cmd command line as an administrator and execute the command
- Enter
- Login nexus
- Start nexus
- Open the browser: http://localhost:8081/nexus
- Click on the upper right corner
Log In
Account: admin Password: admin123
- Warehouse type
group
: Not a specific warehouse, but a warehouse group (logical)hosted
: Storage dependent files (physical) in private serversproy
:Agent warehouse, representing a central warehouse/public warehouse (logical)
Configure proxy warehouse
Configure private server
settings.xml
In the servers tag of the maven file
<!-- 配置连接私服所需的帐号和密码 -->
<servers>
<server>
<id>nexus-public</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<!-- repository 和 pluginRepository 的 id 子标签的值,要和上面配置的scrver的id子标签的值一致 -->
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-public</id>
<name>nexus release snapshot repository</name>
<url>http://192.168.10.125:8081/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-public</id>
<url>http://192.168.10.125:8081/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!-- activeProfiles配置激活profile -->
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>