Maven中settings.xml与pom.xml文件的理解

一.settings.xml

maven的配置文件settings.xml存在于两个地方:

1.安装的地方:${M2_HOME}/conf/settings.xml         全局配置

2.用户的目录:${user.home}/.m2/settings.xml          用户配置

全局配置:对操作系统的所有使用者生效

用户配置:对当前用户有效

如果两者都存在,则内容会合并,并且用户范围的settings会覆盖全局。

 

在这里我们只谈经常使用的<localRepository >,< servers >,< mirrors >,< profiles >几个节点。

  1. localRepository :本地仓库。默认为${user.home}/.m2/repository,一个构件只有在本地仓库存放之后,才能由Maven项目使用

  2. servers

       

  

            

    

            server001       

    

            my_login 

    

            my_password    

 

  

           ${usr.home}/.ssh/id_dsa 

    

            some_passphrase 

    

    

            664 

    

            775

    

                     

         

3.mirror

 

   

         

             

             

            planetmirror.com     

             

            PlanetMirror Australia 

             

            http://downloads.planetmirror.com/pub/maven2      

             

             

            central           

            

     

4.profiles节点

         

         

                  

             

            test       

             

             

             

             

                     

                 

                false         

                 

                1.7           

                 

                    

                     

                    Windows XP               

                     

                    Windows 

                     

                    x86    

                     

                    5.1.2600       

                 

        

                 

                   

                     

                    mavenVersion         

                     

                    2.0.3       

                    

                 

                 

                      

                     

                    /usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/     

                     

                    /usr/local/hudson/hudson-home/jobs/maven-guide-zh-to-production/workspace/ 

                     

             

              

             

              

             

             

             

             

             

             

                 

                usr/local/winner/jobs/maven-guide 

             

             

               

                 

                 

                     

                    codehausSnapshots 

                     

                    Codehaus Snapshots 

                     

                       

                         

                        false 

                         

                         

                        always   

                         

                         

                        warn        

                     

                     

                     

                     

                         

                         

                         

                     

                     

                    http://snapshots.maven.codehaus.org/maven2        

                     

                     

                    default       

                    

             

             

             

             

                 

                 

                 

                     

                         

                         

                         

                        

                     

                         

                         

                         

                     

                     

                     

                     

                     

                 

             

             

             

             

             

                   

                env-test        

                

         

     

 

二.pox.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.0modelVersion> //pom版本模型(maven2/3只能为4.0.0)

   //基本配置

        <groupId>com.examplegroupId> //组ID,用于定位

       <artifactId>mavendemo02artifactId> //组中唯一ID用于定位

       <version>1.0-SNAPSHOTversion> //项目版本

<packaging>warpackaging> //项目打包方式

  //项目信息

<name>mavendemo02 Maven Webappname> //项目名

<url>http://www.example.comurl> // 主页url

//用于定义pom常量

<properties>

         <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>

         <maven.compiler.source>1.7maven.compiler.source>

        <maven.compiler.target>1.7maven.compiler.target>

properties>

//依赖配置

<dependencies>

        <dependency>

               <groupId>junitgroupId>

              <artifactId>junitartifactId>

              <version>4.11version>

              <scope>testscope>

        dependency>

dependencies>

//构建配置

<build>

               <finalName>mavendemo02finalName>

<pluginManagement>

//使用插件列表

<plugins>

             <plugin>

                         <artifactId>maven-clean-pluginartifactId>

                        <version>3.0.0version>

            plugin>

             <plugin>

                       <artifactId>maven-resources-pluginartifactId>

                       <version>3.0.2version>

             plugin>

            <plugin>

                      <artifactId>maven-compiler-pluginartifactId>

                     <version>3.7.0version>

           plugin>

           <plugin>

                     <artifactId>maven-surefire-pluginartifactId>

                    <version>2.20.1version>

          plugin>

          <plugin>

                    <artifactId>maven-war-pluginartifactId>

                   <version>3.2.0version>

         plugin>

          <plugin>

                   <artifactId>maven-install-pluginartifactId>

                   <version>2.5.2version>

         plugin>

         <plugin>

                    <artifactId>maven-deploy-pluginartifactId>

                   <version>2.8.2version>

         plugin>

plugins>

pluginManagement>

build>

project>

 

你可能感兴趣的:(Maven中settings.xml与pom.xml文件的理解)