解析maven2的配置文件之一(settings.xml)

<!-- /* Font Definitions */ @font-face {font-family:Courier; panose-1:2 7 4 9 2 2 5 2 4 4; mso-font-alt:"Courier New"; mso-font-charset:0; mso-generic-font-family:modern; mso-font-format:other; mso-font-pitch:fixed; mso-font-signature:3 0 0 0 1 0;} @font-face {font-family:Wingdings; panose-1:5 0 0 0 0 0 0 0 0 0; mso-font-charset:2; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:0 268435456 0 0 -2147483648 0;} @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} p.MsoHeader, li.MsoHeader, div.MsoHeader {mso-style-noshow:yes; mso-style-priority:99; mso-style-link:"页眉 Char"; margin:0cm; margin-bottom:.0001pt; text-align:center; mso-pagination:none; tab-stops:center 207.65pt right 415.3pt; layout-grid-mode:char; border:none; mso-border-bottom-alt:solid windowtext .75pt; padding:0cm; mso-padding-alt:0cm 0cm 1.0pt 0cm; font-size:9.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} p.MsoFooter, li.MsoFooter, div.MsoFooter {mso-style-noshow:yes; mso-style-priority:99; mso-style-link:"页脚 Char"; margin:0cm; margin-bottom:.0001pt; mso-pagination:none; tab-stops:center 207.65pt right 415.3pt; layout-grid-mode:char; font-size:9.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; mso-themecolor:hyperlink; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {mso-style-noshow:yes; mso-style-priority:99; color:purple; mso-themecolor:followedhyperlink; text-decoration:underline; text-underline:single;} p {mso-style-priority:99; mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋体; mso-bidi-font-family:宋体;} p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {mso-style-priority:34; mso-style-unhide:no; mso-style-qformat:yes; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; mso-char-indent-count:2.0; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋体; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} span.Char {mso-style-name:"页眉 Char"; mso-style-noshow:yes; mso-style-priority:99; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:页眉; mso-ansi-font-size:9.0pt; mso-bidi-font-size:9.0pt;} span.Char0 {mso-style-name:"页脚 Char"; mso-style-noshow:yes; mso-style-priority:99; mso-style-unhide:no; mso-style-locked:yes; mso-style-link:页脚; mso-ansi-font-size:9.0pt; mso-bidi-font-size:9.0pt;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {mso-list-id:140197706; mso-list-template-ids:1788542258;} @list l0:level1 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:36.0pt; mso-level-number-position:left; text-indent:-18.0pt; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l1 {mso-list-id:320500439; mso-list-template-ids:-335372326;} @list l1:level1 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:36.0pt; mso-level-number-position:left; text-indent:-18.0pt; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l2 {mso-list-id:1808930428; mso-list-template-ids:-1535874228;} @list l2:level1 {mso-level-number-format:bullet; mso-level-text:; mso-level-tab-stop:36.0pt; mso-level-number-position:left; text-indent:-18.0pt; mso-ansi-font-size:10.0pt; font-family:Symbol;} @list l3 {mso-list-id:2115633158; mso-list-template-ids:846078752;} @list l3:level1 {mso-level-tab-stop:36.0pt; mso-level-number-position:left; text-indent:-18.0pt;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->

settings.xml 对于 maven 2来说相当于全局性的配置,用于所有的项目。

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/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          http://maven.apache.org/xsd/settings-1.0.0.xsd">
        <localRepository/>
        <interactiveMode/>
        <usePluginRegistry/>
        <offline/>
        <pluginGroups/>
        <servers/>
        <mirrors/>
        <proxies/>
        <profiles/>
        <activeProfiles/>
   </settings>

   简单介绍一下几个主要的配置因素:

<localRepository>${user.home}/.m2/repository</localRepository>
<interactiveMode>true</interactiveMode>
<usePluginRegistry>false</usePluginRegistry>
<offline>false</offline>
<pluginGroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>

localRepository 表示本地库的保存位置,也就是 maven2 主要的 jar 保存位置,默认在 ${user.dir}/.m2 /repository ,如果需要另外设置,就换成其他的路径。

interactiveMode: true if Maven should attempt to interact with the user for input, false if not. Defaults to true.

usePluginRegistry: true if Maven should use the ${user.home}/.m2/plugin-registry.xml file to manage plugin versions, defaults to false. Note that for the current version of Maven 2.0, the plugin-registry.xml file should not be depended upon. Consider it dormant ( 休眠的、不活动的)for now.

offline: true if this build system should operate in offline mode, defaults to false. This element is useful for build servers which cannot connect to a remote repository, either because of network setup or security reasons.

如果不想每次编译,都去查找远程中心库,那就设置为 true 。当然前提是你已经下载了必须的依赖包。

pluginGroups: 此标签包含一系列插件组元素,每个元素都包含一个groupId 。当使用一个插件而且该插件的groupId 没有提供在命令行中的时候就搜索该列表,该列 表自动包含org.apache.maven.pluginsorg.codehaus.mojo 。例如:按照上面的配置,在命令行中执行 org.mortbay.jetty:jetty-maven-plugin:run 时就可简写为mvn jetty:run

Servers
     
POM 中的 repositories 元素定义了下载库,distributionManagement 元素定义了开发库。然而,特定的 username pwd 不能在 pom.xml 中设置 ,所以通过此配置来保存 server 信息。

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

</servers>

id: This is the ID of the server (not of the user to login as) that matches the id element of the repository/mirror that Maven tries to connect to.

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

privateKey, passphrase Like the previous two elements, this pair specifies a path to a private key (default is ${user.home}/.ssh/id_dsa) and a passphrase, if required. The passphrase and password elements may be externalized in the future, but for now they must be set plain-text in the settings.xml file.

filePermissions, directoryPermissions 在开发中当库文件或者目录创建后,需要使用权限进行访问。合法数值是三位数字。

注意: 如果你使用private key 登录服务器,一定要删除password 元素,否则,private key 将会被忽略。

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 。例如,指向 Maven central repository ( http://repo1.maven.org/maven2/ ) 的镜像,就把此元素的值设为 central 。更多的高级映射有 repo1,repo2 or *,!inhouse

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 元素,是 pom.xml profile 元素的精简版本,主要包括 activation repositories pluginRepositories properties 元素。只包含这四个元素是因为它们是整个创建系统的一部分,而不是单独一个模块的设置。

刚开始接触的时候,可能会比较迷惑,其实这是 maven2 中比较强大的功能。从字面上来说,就是个性配置。
     
单独定义 profile 后,并不会生效,需要通过满足条件来激活。如果一个 profile settings 中被激活, pom.xml 文件中的定义将会覆盖他的值。

Activation

       用于激活此 profile

       <profiles>

<profile>

<id>test</id>

<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>

...

</profile>

</profiles>

  • jdk: 如果匹配指定的 jdk 版本,将会激活
  • os: 操作系统
  • property :如果 maven 能检测到相应的属性
  • file: 用于判断文件是否存在或者不存在

除了使用 activation 来激活 profile ,同样可以通过 activeProfiles 来激活
ActiveProfiles

表示激活的 profile, 通过 profile id 来指定。
  <activeProfiles>
    <activeProfile>env-test</activeProfile>
指定的 profile id
  </activeProfiles>

Properties
  maven
properties 作为位置标识符( placeholder 值,类似于 ant properties 。在 pom.xml 文件中可以通过 ${X} 获得其值。
包括以下的 5 种类型值:

  1. env.X ,返回当前的环境变量 。例如: ${env.PATH}(%PATH% in Windows)
  2. project.x: 返回 pom 中定义的元素值,如 ${ project.version}
  3. settings.x :返回 settings.xml 中定义的元素 ,如 ${settings.offline}
  4. java 系统属性:所有经过 java.lang.System.getProperties() 返回的值 , ${java.home}
  5. x :用户自己设定的值,定义在 <properties/> 元素中的或定义在外部文件中的值,可以通过 ${someVar} 获得。

<profiles>

<profile>

...

<properties>

<user.install>${user.home}/our-project</user.install>

</properties>

...

</profile>

</profiles>

如果此 profile 被激活就可取得 ${user.install} 的值。

 repositories pluginRepositories
定义其他开发库和插件开发库。对于团队来说,肯定有自己的开发库。可以通过此配置来定义。

<profiles>
 
<profile>

...

<repositories>

<repository>

<id>codehausSnapshots</id>

<name>Codehaus Snapshots</name>

<releases>

<enabled>false</enabled>

<updatePolicy>always</updatePolicy>

<checksumPolicy>warn</checksumPolicy>

</releases>

<snapshots>

<enabled>true</enabled>

<updatePolicy>never</updatePolicy>

<checksumPolicy>fail</checksumPolicy>

</snapshots>

<url>http://snapshots.maven.codehaus.org/maven2</url>

<layout>default</layout>

</repository>

</repositories>

<pluginRepositories>

...

</pluginRepositories>

...

</profile>

</profiles>

releases, snapshots: 每个产品的版本的 Release 或者 snapshot( 注: release snapshot 的区别, release 一般是比较稳定的版本,而 snapshot 基本上不稳定,只是作为快照)
enabled 库分别对于 releases, snapshots 是否可用

updatePolicy 此元素定义更新发生的频率, Maven 会把本地的 POM's timestamp (stored in a repository's maven-metadata file) 和远程的相比较。可选值有: always , daily (default), interval:X (where X is an integer in minutes) or never .

checksumPolicy : When Maven deploys files to the repository, it also deploys corresponding

checksum files. Your options are to ignore , fail , or warn on missing or incorrect checksums.

Layout 库的布局,有 default or legacy 两个可选值。

  如下的配置,定义了本地开发库,用于 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>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值