> 文章列表 > maven作用讲解---以及怎么配置阿里的maven镜像

maven作用讲解---以及怎么配置阿里的maven镜像

maven作用讲解---以及怎么配置阿里的maven镜像

目录

Maven介绍

传统的java项目的结构和maven的对比

传统

Maven的项目

 如何配置阿里 maven

2. 修改


Maven介绍

传统的java项目的结构和maven的对比

传统

Maven的项目

 如何配置阿里 maven

 (1) 把 D:\\program\\JavaIDEA 2020.2\\plugins\\maven\\lib\\maven3\\conf\\settings.xml 拷贝默认的 maven 配置目录

(2) C:\\Users\\Administrator\\.m2 目录 settings.xml

 (3) 修改 C:\\Users\\Administrator\\.m2\\settings.xml , 增加红色的部分

<mirrors><!-- mirror| Specifies a repository mirror site to use instead of a given repository. Therepository that| this mirror serves has an ID that matches the mirrorOf element of this mirror.IDs are used| for inheritance and direct lookup purposes, and must be unique across theset of mirrors. |<mirror><id>mirrorId</id><mirrorOf>repositoryId</mirrorOf><name>Human Readable Name for this Mirror.</name><url>http://my.repository.com/repo/path</url></mirror>--><mirror><id>alimaven</id><name>aliyun maven</name><url>http://maven.aliyun.com/nexus/content/groups/public/</url><mirrorOf>central</mirrorOf></mirror>
</mirrors>

2. 修改

D:\\java_projects2\\wyx\\pom.xml

       <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version><scope>provided</scope></dependency></dependencies>

<!--解读

  1. dependency 表示依赖, 也就是我们这个项目需要依赖的 jar 包
  2.  groupId 和 artifactId 被统称为坐标, 是为了去定位这个项目/jar
  3.  groupId: 一般是公司 比如 com.baidu , 这里是 avax.servlet
  4. artifactId 一般是项目名, 这里是 javax.servlet-api
  5. 这样的化就可以定位一个 jar 包
  6.  version 表示你引入到我们项目的 jar 包的版本是 3.1.0
  7. scope: 表示作用域,也就是你引入的 jar 包的作用范围
  8.  provided 表示在 tomcat 本身是有这个 jar 的,因此在编译,测试使用,但是在打包发布就不用要带上
  9. 在默认情况下, 引入的 jar 会到 中央仓库去下载 https://mvnrepository.com/
  10. 会下载到哪里到你指定的目录 C:\\Users\\Administrator\\.m2\\repository
  11. 有时为了下载更快, 往往配置镜像,
  12.  在 默 认 的 路 径 下 拷 贝 一 份 setting.xml  C:\\Users\\Administrator\\.m2\\settings.xml
  13. 指定默认的阿里云镜像

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