首先:Maven中央仓库的搜索全部公共jar包的地址是,http://search.maven.org/

===Maven基础-默认中央仓库===================================

当我们创建一个简单的Maven项目后(只需要在pom.xml配置好依赖),运行mvn clean install就可以把项目构建好,不需要我们手工下载任何jar,这全靠中央仓库的存在,它会自动从仓库下载。这个仓库的定义是在${M2_HOME}/lib/maven-2.0.10-uber.jar 里面。你可以在里面找到\org\apache\maven\project\pom-4.0.0.xml 这个文件,在这个文件里面定义了默认中央仓库的地址:

  1. <repositories>

  2. <repository>

  3. <id> central</id>

  4. <name> Maven Repository Switchboard</name>

  5. <layout> default</layout>

  6. <url> http://repo1.maven.org/maven2</url>

  7. <snapshots>

  8. <enabled> false</enabled>

  9. </snapshots>

  10. </repository>

  11. </repositories>

如果你想覆盖中央仓库的默认地址,那么这里我们就会使用的镜像了,还在setting.xml里面配置:

  1. <settings>

  2. <mirrors>

  3. <mirror>

  4. <id> maven-net-cn</id>

  5. <name> Maven China Mirror</name>

  6. <url> http://maven.net.cn/content/groups/public/</url>

  7. <mirrorOf> central</mirrorOf>

  8. </mirror>

  9. </mirrors>

  10. </settings>

<mirrorOf>,表示只为central仓库做镜像,如果想为所有的仓库做镜像那么可以改为:

<mirrorOf>*</mirrorOf>

===Maven配置详解===================================

maven2 比起maven1 来说,需要配置的文件少多了,主要集中在pom.xml和settings.xml中。
    先来说说settings.xml,settings.xml对于maven来说相当于全局性的配置,用于所有的项目。在maven2中存在两个settings.xml,一个位于maven2的安装目录conf下面,作为全局性配置。对于团队设置,保持一致的定义是关键,所以maven2/conf下面的settings.xml就作为团队共同的配置文件。保证所有的团队成员都拥有相同的配置。当然对于每个成员,都需要特殊的自定义设置,如用户信息,所以另外一个settings.xml就作为本地配置。默认的位置为:${user.dir}/.m2/settings.xml目录中(${user.dir} 指windows 中的用户目录)。
    settings.xml基本结构如下:
    <settings 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/settings-1.0.0.xsd">
  <localRepository/>//本地仓库路径
  <interactiveMode/>//如果需要得到交互输入即为true,否则false
  <usePluginRegistry/>//如果用.m2/plugin-registry.xml来管理plugin的版本为true
  <offline/>//离线模式为true
  <pluginGroups/>//插件组,包含了一系列pluginGroup元素
  <servers/>//服务器,tomcat: 部署服务器,其他的: Mave私服

<mirrors/>//镜像,指定仓库的地址,则默认从指定的镜像下载jar包及插件
  <proxies/>//代理,为Maven配置HTTP代理
  <profiles/>//个性配置
  <activeProfiles/>//激活的个性配置
</settings>
简单介绍一下几个主要的配置因素:
localRepository:表示本地库的保存位置,也就是maven2主要的jar保存位置,默认在${user.dir}/.m2/repository,如果需要另外设置,就换成其他的路径。
offline:如果不想每次编译,都去查找远程中心库,那就设置为true。当然前提是你已经下载了必须的依赖包。
Servers
   在POM中的 distributionManagement元素定义了开发库。然而,特定的username和pwd不能使用于pom.xml,所以通过此配置来保存server信息

<servers>
    <server>
      <id>server001</id>
      <username>my_login</username>
      <password>my_password</password>
      <privateKey>${usr.home}/.ssh/id_dsa</privateKey>
      <passphrase>some_passphrase</passphrase>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
      <configuration></configuration>
    </server>
  </servers>

  • id:server 的id,用于匹配distributionManagement库id,比较重要。

  • username, password:用于登陆此服务器的用户名和密码

  • privateKey, passphrase:设置private key,以及passphrase

  • filePermissions, directoryPermissions:当库文件或者目录创建后,需要使用权限进行访问。参照unix文件许可,如664和775

Mirrors 
表示镜像库,指定库的镜像,用于增加其他库

<mirrors>
    <mirror>
      <id>planetmirror.com</id>
      <name>PlanetMirror Australia</name>
      <url>http://downloads.planetmirror.com/pub/maven2</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>

  • id,name:唯一的标志,用于区别镜像

  • url:镜像的url

  • mirrorOf:此镜像指向的服务id

Proxies 
此设置,主要用于无法直接访问中心的库用户配置。

<proxies>
    <proxy>
      <id>myproxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.somewhere.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
    </proxy>
  </proxies>

  • id:代理的标志

  • active:是否激活代理

  • protocol, host, port:protocol://host:port 代理

  • username, password:用户名和密码

  • nonProxyHosts: 不需要代理的host

Profiles 
  类似于pom.xml中的profile元素,主要包括activation,repositories,pluginRepositories 和properties元素
  刚开始接触的时候,可能会比较迷惑,其实这是maven2中比较强大的功能。从字面上来说,就是个性配置。
  单独定义profile后,并不会生效,需要通过满足条件来激活。
 repositories 和pluginRepositories 
 定义其他开发库和插件开发库。对于团队来说,肯定有自己的开发库。可以通过此配置来定义。
 如下的配置,定义了本地开发库,用于release 发布。

<repositories>
        <repository>
          <id>repo-local</id>
       <name>Internal 开发库</name>
       <url>http://192.168.0.2:8082/repo-local</url>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <layout>default</layout>
        </repository>
      </repositories>
      <pluginRepositories>
    <pluginRepository>
    <id>repo-local</id>
    <name>Internal 开发库</name>
    <url>http://192.168.0.2:8082/repo-local</url>
    <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
    </releases>
    <snapshots>
    <enabled>false</enabled>
    </snapshots>
    <layout>default</layout>
    </pluginRepository>
    </pluginRepositories>
releases, snapshots:每个产品的版本的Release或者snapshot(注:release和snapshot的区别,release一般是比较稳定的版本,而snapshot基本上不稳定,只是作为快照)

properties
  maven 的properties作为placeholder值,如ant的properties。
包括以下的5种类型值:

  1. env.X,返回当前的环境变量

  2. project.x:返回pom中定义的元素值,如project.version

  3. settings.x:返回settings.xml中定义的元素

  4. java 系统属性:所有经过java.lang.System.getProperties()返回的值

  5. x:用户自己设定的值

Activation 
  用于激活此profile

<activation>
        <activeByDefault>false</activeByDefault>
        <jdk>1.5</jdk>
        <os>
          <name>Windows XP</name>
          <family>Windows</family>
          <arch>x86</arch>
          <version>5.1.2600</version>
        </os>
        <property>
          <name>mavenVersion</name>
          <value>2.0.3</value>
        </property>
        <file>
          <exists>${basedir}/file2.properties</exists>
          <missing>${basedir}/file1.properties</missing>
        </file>
      </activation>

  • jdk:如果匹配指定的jdk版本,将会激活

  • os:操作系统

  • property:如果maven能检测到相应的属性

  • file: 用于判断文件是否存在或者不存在

除了使用activation来激活profile,同样可以通过activeProfiles来激活
Active Profiles
表示激活的profile,通过profile id来指定。
  <activeProfiles>
    <activeProfile>env-test</activeProfile> 指定的profile id
  </activeProfiles>

转载于:https://blog.51cto.com/yukaili/1934978

Maven settings.xml配置详解相关推荐

  1. Maven的settings.xml配置详解

    Maven的settings.xml配置详解 1 基本介绍 maven的两大配置文件:settings.xml和pom.xml.其中settings.xml是maven的全局配置文件,pom.xml则 ...

  2. Maven setting.xml 配置详解

    声明规范 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://ww ...

  3. Maven的settings.xml配置详解-阿里云仓库

    文件存放位置 全局配置: ${M2_HOME}/conf/settings.xml 用户配置: ${user.home}/.m2/settings.xml note:用户配置优先于全局配置.${use ...

  4. 学习笔记——Maven pom.xml配置详解

    POM的全称是"ProjectObjectModel(项目对象模型)". pom.xml详解 声明规范 <projectxmlns="http://maven.ap ...

  5. Maven pom.xml配置详解(三)

    2019独角兽企业重金招聘Python工程师标准>>> 环境设置 issueManagement <!--项目的问题管理系统(Bugzilla,Jira,Scarab,或任何你 ...

  6. Maven pom.xml配置详解

    POM的全称是"ProjectObjectModel(项目对象模型)". 声明规范 <projectxmlns="http://maven.apache.org/P ...

  7. Maven settings.xml 文件详解

    概述 settings.xml 文件中的 settings 元素包含用于以各种方式配置 Maven 的元素(就像 pom.xml 文件一样),但不应捆绑到任何特定项目,或分发给受众.其中包括本地存储库 ...

  8. Maven 之 settings.xml 文件详解

    文章目录 1 引言 2. settings.xml 元素详解 2.1 根元素settings概览 2.1.1 LocalRepository 2.1.2 InteractiveMode 2.1.3 U ...

  9. JavaWeb web.xml配置详解

    参考: XML 教程 Java web之web.xml配置详解 Javaweb三大组件是:Servlet,Filter,Listener. 1.Servlet Servlet作为中转处理的容器,连接了 ...

最新文章

  1. Pass算子python 函数
  2. 大数据的相关技术(Technology)
  3. select的5中子句where,group by, havaing, order by, limit的使用顺序及实例
  4. 集中式管理助推服装企业腾飞
  5. 16_非监督学习、k-means 4阶段、kmeans API、Kmeans性能评估指标、案例
  6. 【华为云技术分享】《跟唐老师学习云网络》 - TUN/TAP网线
  7. 注解 java 原理_Java注解基本原理
  8. php布署 群辉_docker一键搭建Nginx+PHP环境(含自动部署命令)
  9. iPhone 总是提示 无法验证服务器身份 a.wunderlist.com 解决办法
  10. java尾行注释有什么不好_注释不好吗?
  11. echarts使用rich设置显示数据label颜色
  12. 从前慢-SpringCloud
  13. 工单服务管理系统开发
  14. 000898先生的留言
  15. 【100%通过率】华为OD机试真题 Java 实现【最接最大输出功率的设备 /查找充电设备组合】
  16. 读书笔记-《像高手一样发言》
  17. 博通wifi驱动详解(三)
  18. 普通一本的计算机专业好就业吗,放弃985大学冷门专业,填报普通一本热门专业,值吗?...
  19. ios 判断手机角度_iOS 角度获取及旋转
  20. 我在上海赶飞机 出租司机给我上了一堂MBA课

热门文章

  1. Windows下 maven3.0.4的安装步骤+maven配置本地仓库(转载)
  2. 嫉恨别人不如审视自己
  3. 《代码敲不队》第五次作业:项目需求分析改进与系统设计
  4. SpringMvc 3.x跨域+ajax请求
  5. HTML5中关于wheel事件兼容性处理
  6. 每日英语:Prosecutors Wrap Up Case Against Bo
  7. 国内首部高尔夫商战小说《手腕》(林健锋著)
  8. 最近学习了责任链模式
  9. openssl 自建CA签发证书 网站https的ssl通信
  10. 紫书 习题7-14 UVa 307(暴搜+剪枝)