??xml version="1.0" encoding="utf-8" standalone="yes"?>伊人久久精品,亚洲啪啪91,亚洲一区二区三区视频在线http://www.aygfsteel.com/jianyue/category/34500.html砌代?/description>zh-cnTue, 16 Sep 2008 23:15:18 GMTTue, 16 Sep 2008 23:15:18 GMT60maven pom.xml详解http://www.aygfsteel.com/jianyue/articles/227932.htmlQziQziTue, 16 Sep 2008 08:21:00 GMThttp://www.aygfsteel.com/jianyue/articles/227932.htmlhttp://www.aygfsteel.com/jianyue/comments/227932.htmlhttp://www.aygfsteel.com/jianyue/articles/227932.html#Feedback0http://www.aygfsteel.com/jianyue/comments/commentRss/227932.htmlhttp://www.aygfsteel.com/jianyue/services/trackbacks/227932.html<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion><!--maven2.0必须是这样写Q现在是maven2唯一支持的版?-> <!-- The Basics --> <groupId>...</groupId> <!--指定l名,例如Qorg.apache.maven--> <artifactId>...</artifactId> <!--指定工程名例如:appfuse--> <version>...</version> <!--指定版本? <packaging>...</packaging> <!--The current core packaging values are: pom, jar, maven-plugin, ejb, war, ear, rar, par--> <classifier>...</classifier> <!--projects are displayed as groupId:artifactId:packaging:classifier:version-->
<name>...</name> <!--一些无兛_重要的东西,用户描述你的目的名?可选的-->
<url>...</url> <!--暂时不知何物Q貌似无关重要,只是写明开发团队的|站Q可选的-->
<!--
q里有些东西暂时不谈-->
<dependencies>...</dependencies> <!--例子Q?nbsp;   <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.0</version>
      <type>jar</type>
      <scope>test</scope>
      <optional>true</optional>
    </dependency>
groupIdQartifactId和versionq个三组合标CZ赖的具体工程Q而且q个依赖工程必须是maven中心包管理范围内的。如果碰上非开源包Qmaven支持不了q个包,那么则有三种Ҏ处理Q?.本地安装q个插ginstall plugin例如Q?
mvn install:install-file -Dfile=non-maven-proj.jar -DgroupId=some.group -DartifactId=non-maven-proj -Dversion=1

2.创徏自己的Repositoriesq且部vq个包,使用cM上面?tt>deploy:deploy-file 命o3.讄scope为systemQƈ且指定系l\?/p>

dependency里面的classifierQ用于区分从同一个pom~译出来的但是内容不同的同名包,例如同一个工E编译出两个artifactQ一个支持jdk1.5一个支持jdk1.4Q那么就可以使用q个来命名ؓjdk15和jdk14来区分,它如果出现在包名中,那么它必跟在版本号后。还有一U情冉|一个工E的一些次要artifact附到主要artifact中,可以用这个来区分Q例如一个工E生sourceQjavadocQclass三种东西Q那么就可以使用不同的classifier来分别标识这些东?
dependency里面的typeQ默认ؓjarQ类型,常用如:jarQejb-clientQtest-jarQ可以设|plugins中的extensionsgؓtrue后在增加新类?br /> dependency里面的scopeQ指定classpathQ可以ؓQcompileQ默认的Qcompile scope在所有classpaths内有效,q些dependencies会传播到项目中。providedQ指Cjdk或者某个容器可以提供他Q它只在compilation和test的classpaths有效Q而且不会传播的。runtimeQ指C个dependency在编译过E是不必要的Q但是执行需要,在test和runtime的classpaths有效Q在compile的classpaths无效。testQ指C个dependency在一般程序运行是无效的,但是在test的compilation和execution是有效的Qsystem则跟providedcMQ但是这Udependency必须人工明确地制定。这U依赖不会在repository中查找?br /> dependency里面的systemPathQ只在dependency的scope声明为system的时候才有用除,否则Qbuild的过E将会失败。\径必Ll对的,所以最好用property来声明机器的特定路径?br /> dependency里面的optionalQ如果工E本w是一个dependency那么标CؓoptionalQ例如X需要AQA需要BQ那么X只需要optional的BQ则B在X中就是optional声明的了
dependency里面的exclusionsQ如果X需要AQA包含B依赖Q那么X可以声明不要B依赖Q只要在exclusions中声明exclusion。optional是不会install或者用BQ而exclusion是将B从依赖树中是删除。例如appfuse不想使用hibernateQ但是appfuse是集成hibernate的,所以就排除掉:
            <exclusions>
                <exclusion>
                    <groupId>org.appfuse</groupId>
                    <artifactId>appfuse-hibernate</artifactId>
                </exclusion>
            </exclusions>-->

<!--InheritanceQ如果一个工E是pareent或者aggregationQ即mutil-module的)的,那么必须在packaging赋值pom。child工程从parentl承的包括:dependenciesQdevelopers and contributorsQplugin listsQreports listsQplugin execution with matching idsQplugin configuration-->
<parent>...</parent> <!--参照下面例子QrelativePath是可选的Qmaven会首先搜索这个地址Q在搜烦本地和远Erepositories之前
  <parent>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>my-parent</artifactId>
    <version>2.0</version>
    <relativePath>../my-parent</relativePath>
  </parent>
-->
 <dependencyManagement>...</dependencyManagement>  <!--用于帮助理children的dependencies。例如如果parent使用dependencyManagement定义一个dependencyon junit:junit:4.0Q那么它的children可以只引用groupId和artifactIdQ而version可以通过parent来设|。好处就是集中管理依赖详?->
<modules>...</modules><!--对于多模块projectQouter-module没有必要考虑inner-module的dependenciesQ当列出modules的时候。modules的顺序是不重要的Q因为maven会自动根据依赖关pL拓扑排序Qmodules例子Q?br />     <module>my-project<module>
    <module>another-project<module>
-->
<properties>...</properties> <!--参照http://www.aygfsteel.com/jianyue/articles/maven2_setting.htmlQ是一L-->
<!-- Build Settings --><build>...</build> <!--
defaultGoalQ?/strong>默认的目标,必须跟命令行上的参数相同例如jar:jarQ或者与时期QparseQ相同,例如install
directoryQ?/strong>指定build target目标的目录,默认?{basedir}/targetQ即目根目录下的target
finalNameQ?/strong>指定L后缀名后的工E名字,例如Q默认ؓ${artifactId}-${version}
filtersQ?/strong>用于定义指定filter属性文件位|,例如filter元素赋值filters/filter1.propertiesQ那么这个文仉面就可以定义name=value对,q个name=value对的值就可以在工Epom中通过${name}引用Q默认的filter目录?tt>${basedir}/src/main/filters/
resourcesQ?/strong>描述工程中资源的位置
      <resource>
        <targetPath>META-INF/plexus</targetPath>
        <filtering>false</filtering>
        <directory>${basedir}/src/main/plexus</directory>
        <includes>
          <include>configuration.xml</include>
        </includes>
        <excludes>
          <exclude>**/*.properties</exclude>
        </excludes>
      </resource>
targetPathQ指定build资源到哪个目的目录,默认是base directory
filteringQ指定是否将filter文gQ即上面说的filters里定义的*.property文gQ的变量值在q个resource文g有效Q例如上面就指定那些变量值在configuration文g无效
directoryQ指定属性文件的目录Qbuild的过E需要找到它Qƈ且将其放到targetPath下。默认的directory?tt>${basedir}/src/main/resources
includesQ指定包含文件的patternsQ符合样式ƈ且在directory目录下的文g会是包含进project的资源文?br /> excludesQ指定不包含在内的patternsQ如果includes与excludes有冲H,那么excludes胜利Q那些符合冲H样式的文gq是不会包含q来?br /> testResourcesQ?/strong>q个模块包含试资源元素Q其内容定义与resourcescM。不同的一Ҏ默认的测试资源\径是${basefir}/src/test/resourcesQ测试资源是不部|的?br /> -->
<plugins>...</plugins> <!--
<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.0</version>
        <extensions>false</extensions>
        <inherited>true</inherited>
        <configuration>
          <classifier>test</classifier>
        </configuration>
        <dependencies>...</dependencies>
        <executions>...</executions>
      </plugin>

extensionsQtrue or falseQ决定是否要loadq个plugin的extensions
inheritedQ是否让子poml承true or false
configurationQ通常用于U有不开源的pluginQ不能够详细了解plugin的内部工作原理,但plugin满需要满的properties
dependenciesQ与pom基础的dependencies的结构和功能都相同,只是plugin的dependencies用于pluginQ而pom的dependencies用于本nq个工程Q在plugin的dependencies主要用于改变plugin原来的dependenciesQ例如排除一些用不到的dependency或者修改dependency的版本等Q详l请看pom基础的dependencies
executionsQplugin也有很多个目标,每个目标h不同的配|,executions是讑֮plugin的目?br />           <execution>
            <id>echodir</id>
            <goals>
              <goal>run</goal>
            </goals>
            <phase>verify</phase>
            <inherited>false</inherited>
            <configuration>
              <tasks>
                <echo>Build Dir: ${project.build.directory}</echo>
              </tasks>
            </configuration>
          </execution>
idQ标识符
goalsQ里面列Zpd的goal元素Q例如上面的run goal
phaseQ声明goals执行的时期,例如Qverify
inheritedQ是否传递execution到子pom
configurationQ设|execution下列表的goals 的设|,而不是plugin所有goals的设|?br /> plugin Management: 用于理pluginQ与pom build里的plugins区别是,q里的plugin是列出来Q然后让子pom来决定是否引用的Q例如后面的引用Ҏ?br /> <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <version>2.2</version>
          <executions>
            <execution>
              <id>pre-process-classes</id>
              <phase>compile</phase>
              <goals>
                <goal>jar</goal>
              </goals>
              <configuration>
                <classifier>pre-process</classifier>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
子pom引用ҎQ?br /> 在pom的build里的plugins引用Q?br />     <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
      </plugin>
    </plugins>
build 里面?/strong>DirectoriesQ?/strong>
    <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
    <scriptSourceDirectory>${basedir}/src/main/scripts</scriptSourceDirectory>
    <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
    <outputDirectory>${basedir}/target/classes</outputDirectory>
    <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
q几个元素只在parent bulid element里面定义Q他们设|多U\径结构,他们q不在profile里,所以不能通过profile来修?br /> build 里面?/strong>ExtensionsQ?br /> 它们是一pdbuildq程中要使用的品,他们会包含在running bulid‘s classpath里面。他们可以开启extensionsQ也可以通过提供条g来激zplugins。简单来Ԍextensions是在buildq程被激zȝ产品
    <extensions>
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-ftp</artifactId>
        <version>1.0-alpha-3</version>
      </extension>
    </extensions>
-->
 <reporting>...</reporting> <!--
reporting包含site生成阶段的一些元素,某些maven  plugin可以生成reportsq且在repoting下配|。例如javadocQmaven site{,在reporting下配|reprot plugin的方法与build几乎一P最不同的是Qbuild的plug-in goals在executions下设|,而reporting的configures goals在reportset。更微妙的不同是reporting下的plugin configuration works as a build plugin configurationQ但是相反是不对的(即build plugin configuration does not affect a reporting pluginQ?br /> excludeDefaultsQ?/strong>是否排除site generator默认产生的reports
outpoutDirectoryQ默认的dir变成Q?tt>${basedir}/target/site
Report setsQ?/strong>讄execution goalsQ相当于build里面的executions。不同的是不能够bind a report to another phaseQ只能够是site
<reporting>
    <plugins>
      <plugin>
        ...
        <reportSets>
          <reportSet>
            <id>sunlink</id>
            <reports>
              <report>javadoc</report>
            </reports>
            <inherited>true</inherited>
            <configuration>
              <links>
                <link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
              </links>
            </configuration>
          </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>
reporting里面的厄reportSets和build里面的executions的作用都是控制pom的不同粒度去控制build的过E,我们不单要配|pluginsQ还要配|那些plugins单独的goals?br /> -->
<!-- More Project Information -->
<description>...</description>
project的描q?br /> <inceptionYear>...</inceptionYear>
工程的初始时?br /> <licenses>...</licenses>
<licenses>
  <license>
    <name>Apache 2</name>
    <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    <distribution>repo</distribution>
    <comments>A business-friendly OSS license</comments>
  </license>
</licenses>
<!--列出本工E直接的licensesQ而不要列出dependencies的licensesQ?/p>

  • name, url and comments: are self explanatory, and have been encountered before in other capacities. The fourth license element is:
  • distribution: This describes how the project may be legally distributed. The two stated methods are repo (they may be downloaded from a Maven repository) or manual (they must be manually installed).

    -->
    <organization>...</organization>
    <!--
       <organization>
        <name>Codehaus Mojo</name>
        <url>http://mojo.codehaus.org</url>
      </organization>
    很多工程都受到某些组l运行,q里讄基本信息
    -->
    <developers>...</developers>
    <!--例如Q一个开发者可以有多个rolesQproperties?br />   <developers>
        <developer>
          <id>eric</id>
          <name>Eric</name>
          <email>eredmond@codehaus.org</email>
          <url>http://eric.propellors.net</url>
          <organization>Codehaus</organization>
          <organizationUrl>http://mojo.codehaus.org</organizationUrl>
          <roles>
            <role>architect</role>
            <role>developer</role>
          </roles>
          <timezone>-6</timezone>
          <properties>
            <picUrl>http://tinyurl.com/prv4t</picUrl>
          </properties>
        </developer>
      </developers>
    -->
    <contributors>...</contributors>
    <!--跟developer差不多,只是contributors是副的工作h员,不过良好工程应该需要更多的contributors而不是developerQ例如:
      <contributors>
        <contributor>
          <name>Noelle</name>
          <email>some.name@gmail.com</email>
          <url>http://noellemarie.com</url>
          <organization>Noelle Marie</organization>
          <organizationUrl>http://noellemarie.com</organizationUrl>
          <roles>
            <role>tester</role>
          </roles>
          <timezone>-5</timezone>
          <properties>
            <gtalk>some.name@gmail.com</gtalk>
          </properties>
        </contributor>
      </contributors>
    -->
    <!-- Environment Settings --> <issueManagement>...</issueManagement>
     <!--定义defect tracking system~陷跟踪pȝQ比如有Qbugzilla,testtrack,clearquest{)Q例如:
      <issueManagement>
        <system>Bugzilla</system>
        <url>http://127.0.0.1/bugzilla/</url>
      </issueManagement>
    -->
    <ciManagement>...</ciManagement>
    <!--Continuous Integration ManagementQ设|自动buildpȝQ一些集成程序包括continuum,Cruise control{。例如:

    <ciManagement>
        <system>continuum</system>
        <url>http://127.0.0.1:8080/continuum</url>
        <notifiers>
          <notifier>
            <type>mail</type>
            <sendOnError>true</sendOnError>
            <sendOnFailure>true</sendOnFailure>
            <sendOnSuccess>false</sendOnSuccess>
            <sendOnWarning>false</sendOnWarning>
            <configuration><address>continuum@127.0.0.1</address></configuration>
          </notifier>
        </notifiers>
      </ciManagement>

    maven捕获一些经帔R发生的配|,在notifier元素里配|。A notifier is the manner in which people are notified of certain build statuses. In the following example, this POM is setting a notifier of type mail (meaning email), and configuring the email address to use on the specified triggers sendOnError, sendOnFailure, and not sendOnSuccess or sendOnWarning.
    -->
    <mailingLists>...</mailingLists>
    <!--例如Q?br />   <mailingLists>
        <mailingList>
          <name>User List</name>
          <subscribe>user-subscribe@127.0.0.1</subscribe>
          <unsubscribe>user-unsubscribe@127.0.0.1</unsubscribe>
          <post>user@127.0.0.1</post>
          <archive>http://127.0.0.1/user/</archive>
          <otherArchives>
            <otherArchive>http://base.google.com/base/1/127.0.0.1</otherArchive>
          </otherArchives>
        </mailingList>
      </mailingLists>
    看不懂解释啊Q照搬吧Q?/p>

  • subscribe, unsubscribe: There elements specify the email addresses which are used for performing the relative actions To subscribe to the user list above, a user would send an email to user-subscribe@127.0.0.1.
  • archive: This element specifies the url of the archive of old mailing list emails, if one exists. If there are mirrored archives, they can be specified under otherArchives.
  • post: The email address which one would use in order to post to the mailing list. Note that not all mailing lists have the ability to post to (such as a build failure list).
    -->
    <scm>...</scm>

    <!--例如Q?br />   <scm>
        <connection>scm:svn:http://127.0.0.1/svn/my-project</connection>
        <developerConnection>scm:svn:https://127.0.0.1/svn/my-project</developerConnection>
        <tag>HEAD</tag>
        <url>http://127.0.0.1/websvn/my-project</url>
      </scm>
    connection, developerConnection: 都是q接字符Ԍ其中后者是hwrite权限的scmq接Q常用的scm工具包括cvs与subversionQ还有其?a >scmsQurl的字W串格式是:scm:[provider]:[provider_specific]Q例如cvs的是scm:cvs:pserver:127.0.0.1:/cvs/root:my-project
    tagQ说明project所在的目录tagQ默认是HEADQ表C根目录
    urlQ公开的可览repository
    -->

    <prerequisites>...</prerequisites>
     <!--首要条gQ如果不满Qmaven会在事g开始之前失败,在pom4.0Q唯一的首要条件是maven元素-->
    <repositories>...</repositories>
    <!--要成为maven2的repository artifactQ必d有pom文g?tt>$BASE_REPO/groupId/artifactId/version/artifactId-version.pom
    BASE_REPO可以是本圎ͼ也可以是q程的。repository元素是声明那些L扄repositories
    默认的central Maven repository?a class="externalLink" >http://repo1.maven.org/maven2/Q?br /> <repositories>
        <repository>
          <releases>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
          </snapshots>
          <id>codehausSnapshots</id>
          <name>Codehaus Snapshots</name>
          <url>http://snapshots.maven.codehaus.org/maven2</url>
          <layout>default</layout>
        </repository>
      </repositories>
    release和snapshotsQ是artifact的两UpoliciesQpom可以选择那种政策有效?br /> enableQ本别指定两U类型是否可用,true or false
    updatePolicy:说明更新发生的频率always 或?never 或?dailyQ默认的Q或?interval:XQX是分钟数Q?br /> checksumPolicyQWhen 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.
    layoutQ?/strong>maven1.x与maven2有不同的layoutQ所以可以声明ؓdefault或者是legacyQ遗留方式maven1.xQ?br /> -->
     <pluginRepositories>...</pluginRepositories>
    <!--与RepositorieshcM的结构,只是Repositories是dependencies的homeQ而这个是plugins 的home?->
    <distributionManagement>...</distributionManagement>
    <!--理distribution和supporting files?br /> downloadUrlQ是其他目Z抓取本项目的pom’s artifact而指定的urlQ就是说告诉pom upload的地址也就是别人可以下载的地址?br /> statusQ这里的状态不要受到我们的讄Qmaven会自动设|project的状态,有效的|noneQ没有声明状态,pom默认的;convertedQ本project是管理员从原先的maven版本convert到maven2的;partnerQ以前叫做synchedQ意思是与partner repository已经q行了同步;deployedQ至今ؓ止最l常的状态,意思是制品是从maven2 instance部v的,人工在命令行deploy的就会得到这个;verifiedQ本制品已经l过验证Q也是已经定下来了最l版?br /> repositoryQ声明deployq程中current project会如何变成repositoryQ说明部|到repository的信息?br />     <repository>
          <uniqueVersion>false</uniqueVersion>
          <id>corp1</id>
          <name>Corporate Repository</name>
          <url>scp://repo1/maven2</url>
          <layout>default</layout>
        </repository>
        <snapshotRepository>
          <uniqueVersion>true</uniqueVersion>
          <id>propSnap</id>
          <name>Propellors Snapshots</name>
          <url>sftp://propellers.net/maven</url>
          <layout>legacy</layout>
        </snapshotRepository>
    id, name:Q唯一性的idQ和可读性的name
    uniqueVersionQ指定是否生一个唯一性的version numberq是使用address里的其中version部分。true or false
    urlQ说明location和transport protocol
    layoutQdefault或者legacy-->
    <site><!---声明如何部vproject‘s 的site和document->
    <!--例如Q?br />     <site>
          <id>mojo.website</id>
          <name>Mojo Website</name>
          <url>scp://beaver.codehaus.org/home/projects/mojo/public_html/</url>
        </site>
    与上面repository的元素相同意?br /> -->
    RelocationQ?br /> <!-- 说明工程的变_在这里警告用者当心工E被重命名了{信息。重新指定id和名Uͼq且写个message注明备注   <relocation>
          <groupId>org.apache</groupId>
          <artifactId>my-project</artifactId>
          <version>1.0</version>
          <message>We have moved the Project under Apache</message>
        </relocation>
    -->
    <profiles>...</profiles>
    <!--pom4.0的一个新Ҏ就是具有根据environment来修改设|的能力?/p>

  • 它包含可选的activationQprofile的触发器Q和一pd的changes。例如testq程可能会指向不同的数据库(相对最l的deploymentQ或者不同的dependencies或者不同的repositoriesQƈ且是Ҏ不同的JDK来改变的。那么结构如下:

      <profiles>
        <profile>
          <id>test</id>
          <activation>...</activation>
          <build>...</build>
          <modules>...</modules>
          <repositories>...</repositories>
          <pluginRepositories>...</pluginRepositories>
          <dependencies>...</dependencies>
          <reporting>...</reporting>
          <dependencyManagement>...</dependencyManagement>
          <distributionManagement>...</distributionManagement>
        </profile>
      </profiles>
    ActivationQ?br /> 触发q个profile的条仉|如下例Q(只需要其中一个成立就可以ȀzprofileQ如果第一个条件满了Q那么后面就不会在进行匹配?br />     <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>

    -->
    Ȁzprofile的方法有多个Qsetting文g的activeProfile元素明确指定Ȁzȝprofile的IDQ在命o行上明确ȀzProfile?P flag 参数
    查看某个build会激zȝprofile列表可以用:mvn help:active-profiles
    </project>



    Qzi 2008-09-16 16:21 发表评论
    ]]>
    maven2 setting文g详解http://www.aygfsteel.com/jianyue/articles/maven2_setting.htmlQziQziMon, 08 Sep 2008 03:01:00 GMThttp://www.aygfsteel.com/jianyue/articles/maven2_setting.htmlhttp://www.aygfsteel.com/jianyue/comments/227678.htmlhttp://www.aygfsteel.com/jianyue/articles/maven2_setting.html#Feedback0http://www.aygfsteel.com/jianyue/comments/commentRss/227678.htmlhttp://www.aygfsteel.com/jianyue/services/trackbacks/227678.html以下完全照搬官网Q?a >http://maven.apache.org/settings.html  只是加上一点自q理解而已
    可以h两个setting文gQ?br /> 1.$M2_HOME/conf/settring.xml安装Maven有的系lsettingQ各个用h效的全局的)
    2.${user.home}/.m2/settring.xml用户自己加在Repository里的setting文gQ用L的)

    元素总览Q?/p>
    <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/>
    <usePluginRegistry/>
    <offline/>
    <pluginGroups/>
    <servers/>
    <mirrors/>
    <proxies/>
    <profiles/>
    <activeProfiles/>
    </settings>
    
  • localRepository:配置本地的Repository路径Q可以是l对路径Q通常写的?{user.home}/.m2/repository
  • interactiveMode:是否希望maven与用戯入进行交互,true的话Qmaven有可能与用户交互,默认是true
  • usePluginRegistry:如果需要?tt>${user.home}/.m2/plugin-registry.xml来控制plugin的版本的话,是trueQ现在默认ؓfalseQ因为maven2.0Q不依赖q个文g
  • offline: 是否为离U运行状态,默认为falseQ对于不能够使用q程Repository的,使用true
  • pluginGroups: 包含一lpluginGroup元素Q如果在命o行上没有声明使用某个插gQ又要用到这个插Ӟ在q里的pluginGroup里声明。这个列表默认包括org.maven.plugins
  • ServersQRepositories的详l定义在pom.xml的distributionManagement中,但是
  •     <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>

    q些是在q里定义的?br /> idQ与distributionManagement中的repository中的元素id对应Q用于表CZ个server
    username,passwordQ如果server需要验证的话,q一对元素就是用于验证的
    privateKey, passphraseQ也是用于服务器验证的,前者指定私钥privateKeyQ默?tt>${user.home}/.ssh/id_dsaQ,后者指定口号passphrase
    filePermissions, directoryPermissionsQ用linux中的三位数字形式标示文g与\径的权限Q例?64Q?75{?br /> 注意Q如果用私钥登录服务器的话Q那么passwordq略,否则Q私钥会被忽略?br /> configurationQ官|也没有解释?/p>

  • Mirrors
  •     <mirror>
          <id>planetmirror.com</id>
          <name>PlanetMirror Australia</name>
          <url>http://downloads.planetmirror.com/pub/maven2</url>
          <mirrorOf>central</mirrorOf>
        </mirror>
    idQnameQserver镜像的唯一标识与可L强的名Uͼid才是唯一的)

    urlQmirror的地址
    mirrorOfQ指定这个镜像代表的server的idQ那么以后工E引用这个server的时候将不会使用server而是变成使用mirror的地址

    In 2.0.9+, an enhanced syntax is supported:

    • * matches all repo ids.
    • external:* matches all repos except those using localhost or file based repositories. This is used in conjunction with a repository manager when you want to exclude redirecting repositories that are defined for Integration Testing.
    • multiple repos may be specified using , as the delimiter
    • ! may be used in conjunction with one of the above wildcards to exclude a repo id.

    The order is not important from left to right as the wildcards defer to further processing and explicit includes or excludes stop the processing. Additionally, the mirror list will now be ordered using a LinkedHashMap instead of HashMap such that the user may influence match order by changing the order of the definitions in the settings.xml

    Examples:

    • * = everything
    • external:* = everything not on the localhost and not file based.
    • repo,repo1 = repo or repo1
    • *,!repo1 = everything except repo1

  • 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>
    idQ表CZ同的proxy
    activeQ当有多个proxy的时候,只有active为true的时候才是有效的
    protocolQhostQportQ协议,LQ端?br /> usernameQpasswordQ如果需要的话就加上
    nonProxyHostsQ排除不用代理的站点Q?#8220;|”或?#8220;Q?#8221;W号分开不同站点Q可以用通配W?#8220;*”

  • profiles
  • activation, repositories, pluginRepositories and properties elements
        activation指定Ȁz这个profile的条件。其他激zȝҎQ(1Qsetting.xml可以通过activeProfile元素指定profile的idQ来明确地激z这个profile。(2Q在命o行上加上-P profile的idQ也可以Ȁz这个profileQ其中可以通过“,”分开几个profile的id来指定多个?br />     repositories包含的repository指定依赖Q它之前的activation如果W合ȀzL件的话就开启这个依?br />     pluginRepositories和properties也一P如果activationW合ȀzLӞ则它们将被激z?br /> 例子1Q如果用jdk-1.4的话Qjdk的依赖将会被Ȁz?br />

        <profile>
          <id>jdk-1.4</id>

          <activation>
            <jdk>1.4</jdk>
          </activation>

          <repositories>
            <repository>
       <id>jdk14</id>
       <name>Repository for JDK 1.4 builds</name>
       <url>http://www.myhost.com/maven/jdk14</url>
       <layout>default</layout>
       <snapshotPolicy>always</snapshotPolicy>
     </repository>
          </repositories>
        </profile>

    例子2Q如果target-env的属性gؓdev的时候,激ztomcatPath的属性,其他地方肯定会有元素引用q个属性,例如后面引用

        <profile>
          <id>env-dev</id>

          <activation>
            <property>
       <name>target-env</name>
       <value>dev</value>
     </property>
          </activation>

          <properties>
            <tomcatPath>/path/to/tomcat/instance</tomcatPath>
          </properties>
        </profile>
        -->
      </profiles>

    引用tomcatPath
         | <plugin>
         |   <groupId>org.myco.myplugins</groupId>
         |   <artifactId>myplugin</artifactId>
         |  
         |   <configuration>
         |     <tomcatLocation>${tomcatPath}</tomcatLocation>
         |   </configuration>
         | </plugin>


  • Properties
  • 属性的引用可以通过${}Q其中:
    1Qenv.***是引用命令行comandline参数既环境变量等参数的|例如%{env.PATH}引用环境变量path的?br /> 2Qproject.***引用pom文g中project的元素|例如pom中有?tt><project><version>1.0</version></project>Q那么可?{project.version}
    3Qsetting.***引用setting文g中的元素|例如Q?tt><settings><offline>false</offline></settings> is accessible via ${settings.offline}
    4Qjava.***,java System PropertiesQ在java语言中可以通过java.lang.System.getProperties() 获得的值都可以通过此来获得Q例如:${java.home}
    5)***是在<properties/>中定义了的可以直接引用的属性,Ҏ%{someVar}?/font>

  • Repositories
  •      <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>
    1)releases, snapshots:Q理解不了,原文照搬QThese are the policies for each type of artifact, Release or snapshot. With these two sets, a POM has the power to alter the policies for each type independent of the other within a single repository. For example, one may decide to enable only snapshot downloads, possibly for development purposes.
    2Q?strong>enabled
    Qtrue或者false来指明这个repository哪个cd被开?br /> 3Q?strong>updatePolicy
    Q升U策略。The choices are: always, daily (default), interval:X (where X is an integer in minutes) or never
    4Q?strong>checksumPolicy
    QWhen Maven deploys files to the repository, it also deploys corresponding checksum files. options are to ignore, fail, or warn on missing or incorrect checksums
    5Q?strong>layout
    QIn the above description of repositories, it was mentioned that they all follow a common layout. This is mostly correct. Maven 2 has a default layout for its repositories; however, Maven 1.x had a different layout. Use this element to specify which if it is default or legacy.

  • Plugin Repositories
  • l构如同RepositoriesQ但是可以这L解,repositories用于工程q行之前的,plugin Repositories用于q行。例如tomcat jetty{都是pluginsQ而jdkQjar{运行之前的工程~译时候就已经用到?/font>

  • activeProfiles如上所_可以指定一定激zȝprofile
  • activeProfiles

    Qzi 2008-09-08 11:01 发表评论
    ]]>
    վ֩ģ壺 | ˫Ѽɽ| Ӧ| | | | ӳ| ƽ| | | ҵ| | ׯ| ɽ| | | ˮ| Դ| | | | ں| | ˫| Դ| | | | Ǧɽ| ǫ| | | | ɽ| | ̨| | ̨| ʷ| | |