<project> <modelVersion>4.0.0</modelVersion> <!-- The Basics --> <groupId>...</groupId> <artifactId>...</artifactId> <version>...</version> <packaging>...</packaging> <dependencies>...</dependencies> <parent>...</parent> <dependencyManagement>...</dependencyManagement> <modules>...</modules> <properties>...</properties> <!-- Build Settings --> <build>...</build> <reporting>...</reporting> <!-- More Project Information --> <name>...</name> <description>...</description> <url>...</url> <inceptionYear>...</inceptionYear> <licenses>...</licenses> <organization>...</organization> <developers>...</developers> <contributors>...</contributors> <!-- Environment Settings --> <issueManagement>...</issueManagement> <ciManagement>...</ciManagement> <mailingLists>...</mailingLists> <scm>...</scm> <prerequisites>...</prerequisites> <repositories>...</repositories> <pluginRepositories>...</pluginRepositories> <distributionManagement>...</distributionManagement> <profiles>...</profiles> </project>Â
Â
Â
Â
Â
Â
Â
<!-- The Basics --> <groupId>...</groupId> <artifactId>...</artifactId> <version>...</version> <packaging>...</packaging> <dependencies>...</dependencies> <parent>...</parent> <dependencyManagement>...</dependencyManagement> <modules>...</modules> <properties>...</properties>Â
基本内容åQ?br />    POM包括了所有的™å¹ç›®ä¿¡æ¯ã€?br />maven 相关åQ?br />pom定义了最ž®çš„maven2å…ƒç´ åQŒå…许groupId,artifactId,version。所有需è¦çš„å…ƒç´
groupId:™å¹ç›®æˆ–者组¾l‡çš„å”¯ä¸€æ ‡å¿—åQŒåƈ且酾|®æ—¶ç”Ÿæˆçš„èµ\径也是由æ¤ç”Ÿæˆï¼Œå¦‚org.codehaus.mojo生æˆçš„相对èµ\径䨓åQ?org/codehaus/mojoÂ
artifactId: ™å¹ç›®çš„通用åç§°Â
version:™å¹ç›®çš„版本Â?br />packaging: 打包的机åˆÓž¼Œå¦‚pom, jar, maven-plugin, ejb, war, ear, rar, parÂ
classifier: 分类
POM关系åQ?br />主è¦ä¸ÞZ¾èµ–,¾l§æ‰¿åQŒåˆæˆ?br />  ä¾èµ–关系åQ?br />  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.0</version>
      <type>jar</type>
      <scope>test</scope>
      <optional>true</optional>
    </dependency>
    ...
  </dependencies>
groupId, artifactId, version:æè¿°äº†ä¾èµ–çš„™å¹ç›®å”¯ä¸€æ ‡å¿—
å¯ä»¥é€šè¿‡ä»¥ä¸‹æ–¹å¼˜q›è¡Œå®‰è£…åQ?br />
使用以下的命令安装:Â
mvn install:install-file ?Dfile=non-maven-proj.jar ?DgroupId=some.group ?DartifactId=non-maven-proj ?Dversion=1Â
创å¾è‡ªå·±çš„库,òq‰™…¾|®ï¼Œä½¿ç”¨deploy:deploy-fileÂ
讄¡½®æ¤ä¾èµ–èŒƒå›´äØ“systemåQŒå®šä¹‰ä¸€ä¸ªç³»¾lŸèµ\å¾„ã€‚ä¸æå€¡ã€?br />type:相应的ä¾èµ–äñ”å“包形å¼åQŒå¦‚jaråQŒwarÂ
scope:用于é™åˆ¶ç›¸åº”çš„ä¾èµ–范å›ß_¼ŒåŒ…æ‹¬ä»¥ä¸‹çš„å‡ ¿Uå˜é‡ï¼š
compile åQšé»˜è®¤èŒƒå›ß_¼Œç”¨äºŽ¾~–译Â
providedåQšç±»ä¼égºŽ¾~–译åQŒä½†æ”¯æŒä½ 期待jdk或者容器æä¾›ï¼Œ¾cÖM¼¼äºŽclasspathÂ
runtime:在执行时åQŒéœ€è¦ä‹É用Â?br />test:用于testä»ÕdŠ¡æ—¶ä‹É用Â?br />system:需è¦å¤–在æä¾›ç›¸åº”å¾—å…ƒç´ ã€‚é€šè¿‡systemPathæ¥å–å¾?br />systemPath:Â ä»…ç”¨äºŽèŒƒå›´äØ“system。æä¾›ç›¸åº”的路径Â
optional:Â æ ‡æ³¨å¯é€‰ï¼Œå½“项目自íw«ä¹Ÿæ˜¯ä¾èµ–时。用于连¾lä¾èµ–时使用
Â Â Â ç‹¬å æ€§Â   Â?br />   外在告诉mavenä½ åªåŒ…括指定的项目,ä¸åŒ…括相关的ä¾èµ–。æ¤å› ç´ ä¸»è¦ç”¨äºŽè§£å†³ç‰ˆæœ¬å†²çªé—®é¢˜
  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-embedder</artifactId>
      <version>2.0</version>
      <exclusions>
        <exclusion>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-core</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
表示™å¹ç›®maven-embedder需è¦é¡¹ç›?span class="hilite1">maven-coreåQŒä½†æˆ‘们䏿ƒ³å¼•用maven-core
¾l§æ‰¿å…³ç³»
    å¦ä¸€ä¸ªå¼ºå¤§çš„å˜åŒ–,maven带æ¥çš„æ˜¯™å¹ç›®¾l§æ‰¿ã€‚主è¦çš„讄¡½®åQ?br />定义爉™¡¹ç›?br /><project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>my-parent</artifactId>
  <version>2.0</version>
  <packaging>pom</packaging>
</project>
    packaging ¾cÕdž‹åQŒéœ€è¦pom用于parentå’Œåˆæˆå¤šä¸ªé¡¹ç›®ã€‚我们需è¦å¢žåŠ ç›¸åº”çš„å€¼ç»™çˆ¶pomåQŒç”¨äºŽå™å¹ç›®¾l§æ‰¿ã€‚主è¦çš„å…ƒç´ å¦‚ä¸‹åQ?br />
ä¾èµ–åž‹Â?br />å¼€å‘者和åˆä½œè€…Â?br />æ’äšg列表Â
报表列表Â
æ’äšg执行使用相应的匹é…idsÂ
æ’äšgé…ç½®Â
å项目酾|?br /><project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>my-parent</artifactId>
    <version>2.0</version>
    <relativePath>../my-parent</relativePath>
  </parent>
  <artifactId>my-project</artifactId>
</project>
relativePathå¯ä»¥ä¸éœ€è¦ï¼Œä½†æ˜¯ç”¨äºŽæŒ‡æ˜Žparent的目录,用于快速查询ã€?br />
dependencyManagementåQ?br />用于爉™¡¹ç›®é…¾|®å…±åŒçš„ä¾èµ–关系åQŒä¸»è¦é…¾|®ä¾èµ–包相åŒå› ç´ åQŒå¦‚版本åQŒscopeã€?br />
åˆæˆåQˆæˆ–者多个模å—)
    一个项目有多个模å—åQŒä¹Ÿå«åšå¤šé‡æ¨¡å—åQŒæˆ–è€…åˆæˆé¡¹ç›®ã€?br />如下的定义:
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>my-parent</artifactId>
  <version>2.0</version>
  <modules>
    <module>my-project1<module>
    <module>my-project2<module>
  </modules>
</project>
Â
Â
Â
Â
<!-- Build Settings --> <build>...</build> <reporting>...</reporting>Â
build 讄¡½®
    主è¦ç”¨äºŽ¾~–译讄¡½®åQŒåŒ…括两个主è¦çš„å…ƒç´ åQŒbuildå’Œreport
  build
    主è¦åˆ†äØ“ä¸¤éƒ¨åˆ†ï¼ŒåŸºæœ¬å…ƒç´ å’Œæ‰©å±•å…ƒç´ é›†å?br />注æ„åQšåŒ…括项目buildå’Œprofile build
<project>
  <!-- "Project Build" contains more elements than just the BaseBuild set -->
  <build>...</build>
  <profiles>
    <profile>
      <!-- "Profile Build" contains a subset of "Project Build"s elements -->
      <build>...</build>
    </profile>
  </profiles>
</project>
基本元ç´
<build>
  <defaultGoal>install</defaultGoal>
  <directory>${basedir}/target</directory>
  <finalName>${artifactId}-${version}</finalName>
  <filters>
    <filter>filters/filter1.properties</filter>
  </filters>
  ...
</build>
defaultGoal:Â å®šä¹‰é»˜è®¤çš„ç›®æ ‡æˆ–è€…é˜¶ŒDüc€‚如installÂ
directory: ¾~–译输出的目录Â?br />finalName:Â ç”Ÿæˆæœ€åŽçš„æ–‡äšgçš„æ ·å¼Â?br />filter: 定义˜q‡æ×oåQŒç”¨äºŽæ›¿æ¢ç›¸åº”的属性文ä»Óž¼Œä½¿ç”¨maven定义的属性。设¾|®æ‰€æœ‰placeholdçš„å€?br />
资æº(resources)
Â Â Â Â ä½ é¡¹ç›®ä¸éœ€è¦æŒ‡å®šçš„资æºã€‚如springé…置文äšg,log4j.properties
<project>
  <build>
    ...
    <resources>
      <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>
    </resources>
    <testResources>
      ...
    </testResources>
    ...
  </build>
</project>
resources: resource的列表,用于包括所有的资æºÂ
targetPath:Â æŒ‡å®šç›®æ ‡è·¯å¾„åQŒç”¨äºŽæ”¾¾|®èµ„æºï¼Œç”¨äºŽbuildÂ
filtering:Â æ˜¯å¦æ›¿æ¢èµ„æºä¸çš„属性placeholdÂ
directory:Â èµ„æºæ‰€åœ¨çš„ä½ç½®Â
includes:Â æ ·å¼åQŒåŒ…括那些资æºÂ?br />excludes: 排除的资æºÂ?br />testResources: ‹¹‹è¯•资æºåˆ—表
æ’äšg
  在buildæ—Óž¼Œæ‰§è¡Œçš„æ’ä»Óž¼Œæ¯”较有用的部分,如ä‹É用jdk 5.0¾~–译½{‰ç‰
<project>
  <build>
    ...
    <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>
    </plugins>
  </build>
</project>
extensions: true or falseåQŒæ˜¯å¦è£…è½½æ’件扩展。默认falseÂ
inherited: true or falseåQŒæ˜¯å¦æ¤æ’äšgé…ç½®ž®†ä¼šåº”用于pomsåQŒé‚£äº›ç‘ô承于æ¤çš„™å¹ç›®Â
configuration: 指定æ’äšgé…ç½®Â
dependencies: æ’äšg需è¦ä¾èµ–的包Â?br />executions: 用于é…ç½®executionç›®æ ‡åQŒä¸€ä¸ªæ’ä»¶å¯ä»¥æœ‰å¤šä¸ªç›®æ ‡ã€?br />如下åQ?br />    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <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>
        </executions>
      </plugin>
  说明åQ?br />
id:规定executionÂ çš„å”¯ä¸€æ ‡å¿—Â
goals:Â è¡¨ç¤ºç›®æ ‡Â
phase: 表示阶段åQŒç›®æ ‡å°†ä¼šåœ¨ä»€ä¹ˆé˜¶ŒD‰|‰§è¡ŒÂ?br />inherited: 和上é¢çš„å…ƒç´ ä¸€æ øP¼Œè®„¡½®false mavenž®†ä¼šæ‹’ç»æ‰§è¡Œ¾l§æ‰¿¾l™åæ’äšgÂ
configuration:Â è¡¨ç¤ºæ¤æ‰§è¡Œçš„é…置属æ€?br />
æ’äšg½Ž¡ç†
    pluginManagementåQšæ’件管ç†ä»¥åŒæ ·çš„æ–¹å¼åŒ…括æ’ä»¶å…ƒç´ ï¼Œç”¨äºŽåœ¨ç‰¹å®šçš„™å¹ç›®ä¸é…¾|®ã€‚所有ç‘ô承于æ¤é¡¹ç›®çš„å项目都能ä‹É用。主è¦å®šä¹‰æ’件的共åŒå…ƒç´
æ‰©å±•å…ƒç´ é›†åˆ
主è¦åŒ…æ‹¬ä»¥ä¸‹çš„å…ƒç´ ï¼š
Directories
用于讄¡½®å„ç§ç›®å½•¾l“æž„åQŒå¦‚下:
  <build>
    <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>
    ...
  </build>
Extensions
è¡¨ç¤ºéœ€è¦æ‰©å±•çš„æ’äšgåQŒå¿…™åÕdŒ…括进相应的build路径ã€?br />
<project>
  <build>
    ...
    <extensions>
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-ftp</artifactId>
        <version>1.0-alpha-3</version>
      </extension>
    </extensions>
    ...
  </build>
</project>
Reporting
    用于在site阶段输出报表。特定的maven æ’äšg能输出相应的定制和酾|®æŠ¥è¡¨ã€?br />  <reporting>
    <plugins>
      <plugin>
        <outputDirectory>${basedir}/target/site</outputDirectory>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <reportSets>
          <reportSet></reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>
Report Sets
    用于é…ç½®ä¸åŒçš„ç›®æ ‡ï¼Œåº”ç”¨äºŽä¸åŒçš„æŠ¥è¡¨
<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>
Â
Â
Â
Â
Â
<!-- More Project Information --> <name>...</name> <description>...</description> <url>...</url> <inceptionYear>...</inceptionYear> <licenses>...</licenses> <organization>...</organization> <developers>...</developers> <contributors>...</contributors>Â
更多的项目信æ?br />name:™å¹ç›®é™¤äº†artifactId外,å¯ä»¥å®šä¹‰å¤šä¸ªåç§°
description: ™å¹ç›®æè¿°
url: ™å¹ç›®url
inceptionYear:创始òq´ä†¾
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>
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
<!-- Environment Settings --> <issueManagement>...</issueManagement> <ciManagement>...</ciManagement> <mailingLists>...</mailingLists> <scm>...</scm> <prerequisites>...</prerequisites> <repositories>...</repositories> <pluginRepositories>...</pluginRepositories> <distributionManagement>...</distributionManagement> <profiles>...</profiles>Â
Organization
é…ç½®¾l„织信æ¯
  <organization>
    <name>Codehaus Mojo</name>
    <url>http://mojo.codehaus.org</url> ;
  </organization>
Developers
é…置开å‘者信æ?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>
    <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>
环境讄¡½®
Issue Management
    定义相关的bug跟踪¾pÈ»ŸåQŒå¦‚bugzilla,testtrack,clearQuest½{?br />  <issueManagement>
    <system>Bugzilla</system>
    <url>http://127.0.0.1/bugzilla</url> ;
  </issueManagement>
Continuous Integration Management
˜qžç®‹æ•´åˆ½Ž¡ç†åQŒåŸºäºŽtriggers或者timings
  <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>
Mailing Lists
  <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>
SCM
  软äšgé…ç½®½Ž¡ç†åQŒå¦‚cvs 和svn
  <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>
Repositories
é…ç½®åŒsetting.xmlä¸çš„å¼€å‘库
Plugin Repositories
é…ç½®åŒÂ repositories
Distribution Management
用于é…ç½®åˆ†å‘½Ž¡ç†åQŒé…¾|®ç›¸åº”的产å“å‘布信æ¯,主è¦ç”¨äºŽå‘布åQŒåœ¨æ‰§è¡Œmvn deployåŽè¡¨½Cø™¦å‘布的佾|?br />1 é…置到文件系¾l?br /><distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>file://${basedir}/target/deploy</url>
</repository>
</distributionManagement>
2 使用ssh2é…ç½®
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>scp://sshserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
3 使用sftpé…ç½®
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>sftp://ftpserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
4 使用外在的sshé…ç½®
    ¾~–译扩展用于指定使用wagon外在sshæä¾›åQŒç”¨äºŽæä¾›ä½ 的文件到相应的远½E‹æœåС噍ã€?br /><distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>scpexe://sshserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh-external</artifactId>
<version>1.0-alpha-6</version>
</extension>
</extensions>
</build>
5 使用ftpé…ç½®
<distributionManagement>
<repository>
<id>proficio-repository</id>
<name>Proficio Repository</name>
<url>ftp://ftpserver.yourcompany.com/deploy</url>
</repository>
</distributionManagement>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>1.0-alpha-6</version>
</extension>
</extensions>
</build>
repositoryÂ å¯¹åº”äºŽä½ çš„å¼€å‘库åQŒç”¨æˆ·ä¿¡æ¯é€šè¿‡settings.xmlä¸çš„serverå–å¾—
Profiles
¾cÖM¼¼äºŽsettings.xmlä¸çš„profilesåQŒå¢žåŠ äº†å‡ ä¸ªå…ƒç´ åQŒå¦‚ä¸‹çš„æ ·å¼åQ?br />  <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>
Nexus 是Maven仓库½Ž¡ç†å™¨ï¼Œå¦‚æžœä½ ä‹É用MavenåQŒä½ å¯ä»¥ä»?a >Mavenä¸å¤®ä»“库 ä¸‹è²æ‰€éœ€è¦çš„æž„äšgåQˆartifactåQ‰ï¼Œä½†è¿™é€šå¸¸ä¸æ˜¯ä¸€ä¸ªå¥½çš„åšæ³•ï¼Œä½ åº”è¯¥åœ¨æœ¬åœ°æž¶è®¾ä¸€ä¸ªMaven仓库æœåŠ¡å™¨ï¼Œåœ¨ä»£ç†è¿œ½E‹ä»“åº“çš„åŒæ—¶¾l´æŠ¤æœ¬åœ°ä»“库åQŒä»¥èŠ? çœå¸¦å®½å’Œæ—‰™—´åQŒNexusž®±å¯ä»¥æ»¡‘Œ™¿™æ ïLš„需è¦ã€‚æ¤å¤–,他还æä¾›äº†å¼ºå¤§çš„仓库½Ž¡ç†åŠŸèƒ½åQŒæž„ä»¶æœç´¢åŠŸèƒ½ï¼Œå®ƒåŸºäºŽRESTåQŒå‹å¥½çš„UI是一个extjsçš? REST客户端,它å 用较ž®‘的内å˜åQŒåŸºäºŽç®€å•文件系¾lŸè€Œéžæ•°æ®åº“。这些优点ä‹Éå…¶æ—¥‘‹æˆä¸ºæœ€‹¹è¡Œçš„Maven仓库½Ž¡ç†å™¨ã€?/p>
Â
ä½ å¯ä»¥ä»Žhttp://nexus.sonatype.org/downloads/ ä¸‹è²æœ€æ–°ç‰ˆæœ¬çš„NexusåQŒç¬”者ä‹É用的æ˜?.3.0版本ã€?/p>
Nexusæä¾›äº†ä¸¤¿U安装方å¼ï¼Œä¸€¿U是内嵌Jettyçš„bundleåQŒåªè¦ä½ 有JREž®Þpƒ½ç›´æŽ¥˜qè¡Œã€‚ç¬¬äºŒç§æ–¹å¼æ˜¯WARåQŒä½ åªé¡»½Ž€å•çš„ž®†å…¶å‘布到web容器ä¸å³å¯ä‹É用ã€?/p>
Â
解压nexus-webapp-1.3.0-bundle.zip 至ä“Qæ„目录,å¦?em>D:\dev_tools åQŒç„¶åŽæ‰“å¼€CMDåQŒcd至目å½?em>D:\dev_tools\nexus-webapp-1.3.0\bin\jsw\windows-x86-32 åQŒè¿è¡?strong>Nexus.bat ã€‚ä½ ä¼šçœ‹åˆ°Nexusçš„å¯åŠ¨æ—¥å¿—ï¼Œå½“ä½ çœ‹åˆ°â€œStarted SelectChannelConnector@0.0.0.0:8081â€ä¹‹åŽï¼Œè¯´æ˜ŽNexuså¯åЍæˆåŠŸäº†ï¼Œç„¶åŽæ‰“å¼€‹¹è§ˆå™¨ï¼Œè®‰K—® http://127.0.0.1:8081/nexusåQŒä½ 会看到如下的™åµé¢åQ?/p>
è¦åœæ¢NexusåQŒCtrl+Cå›_¯åQŒæ¤å¤–InstallNexus.batå¯ä»¥ç”¨æ¥ž®†Nexus安装æˆä¸€ä¸ªwindowsæœåŠ¡åQŒå…¶ä½™çš„脚本则对应了å¯åЍåQŒåœæ¢ï¼Œæš‚åœåQŒæ¢å¤ï¼Œå¸è²NexusæœåŠ¡ã€?/p>
Â
ä½ éœ€è¦æœ‰ä¸€ä¸ªèƒ½˜q行的web容器åQŒè¿™é‡Œä»¥Tomcatä¸ÞZ¾‹åQŒåŠ å…¥Tomcat的安装目录ä½äº?em>D:\dev_tools\apache-tomcat-6.0.18 åQŒé¦–先我们将下è²çš?em>nexus-webapp-1.3.0.war é‡å‘½å䨓nexus.war åQŒç„¶åŽå¤åˆ¶åˆ°D:\dev_tools\apache-tomcat-6.0.18\webapps\nexus.war åQŒç„¶åŽå¯åЍCMDåQŒcdåˆ?em>D:\dev_tools\apache-tomcat-6.0.18\bin\ 目录åQŒè¿è¡?strong>startup.bat 。一切OKåQŒçŽ°åœ¨å¯ä»¥æ‰“å¼€‹¹è§ˆå™¨è®¿é—®http://127.0.0.1:8080/nexusåQŒä½ 会得到和上图一æ ïLš„界é¢ã€?/p>
Â
è¦ç®¡ç†NexusåQŒä½ 首先需è¦ä»¥½Ž¡ç†å‘˜èín份登陆,点击界é¢å³ä¸Šè§’çš„loginåQŒè¾“入默认的ç™Õd½•å和密ç åQšadmin/admin123åQŒç™»é™†æˆåŠŸåŽåQŒä½ ä¼šçœ‹åˆ°å·¦è¾¹çš„å¯ÆDˆªæ å¢žåŠ äº†å¾ˆå¤šå†…å®¹åQ?/p>
˜q™é‡ŒåQŒå¯ä»¥ç®¡ç†ä»“库,é…ç½®Nexus¾pÈ»ŸåQŒç®¡ç†ä“Q务,½Ž¡ç†ç”¨æˆ·åQŒè§’è‰ÔŒ¼Œæƒé™åQŒæŸ¥çœ‹ç³»¾lŸçš„RSSæºï¼Œ½Ž¡ç†åŠæŸ¥çœ‹ç³»¾lŸæ—¥å¿—,½{‰ç‰ã€‚ä½ ä¼šçœ‹åˆ°Nexus的功能å分丰富和强大åQŒæœ¬æ–‡ï¼Œ½W”者åªä»‹ç»ä¸€äº›æœ€åŸºæœ¬çš„管ç†å’Œæ“作ã€?/p>
Â
ç‚¹å‡»å·¦è¾¹å¯ÆDˆªæ çš„RepositoriesåQŒç•Œé¢çš„䏻颿¿ä¼šæ˜„¡¤ºæ‰€æœ‰ä¸€ä¸ªæ‰€æœ‰ä»“库åŠä»“库¾l„的列表åQŒä½ 会看到它们的Typeå—æ®µçš„值有groupåQŒhostedåQŒproxyåQŒvirtual。这里我们ä¸å…›_¿ƒvirtualåQŒåªä»‹ç»ä¸‹å¦å¤–三¿U类型:
ç”±æ¤æˆ‘们知é“åQŒæˆ‘们需è¦é…¾|®ä¸€ä¸ªMavenä¸å¤®ä»“库的proxyåQŒå…¶å®žNexuså·²ç»å†…置了Maven CentralåQŒä½†æˆ‘们需è¦åšä¸€äº›é…¾|®ã€‚点å‡ÖM»“库列表ä¸çš„Maven CentralåQŒä½ 会注æ„到它的Policy是releaseåQŒè¿™è¯´æ˜Žå®ƒä¸ä¼šä»£ç†è¿œ½E‹ä»“库的snapshotæž„äšgåQŒè¿™æ˜¯æœ‰åŽŸå› çš„ï¼Œ˜qœç¨‹ä»“库çš? snapshot版本构äšgä¸ç¨³å®šä¸”ä¸å—ä½ æŽ§åˆÓž¼Œä½¿ç”¨˜q™æ ·çš„æž„件嫿œ‰æ½œåœ¨çš„é£Žé™©ã€‚ç„¶åŽæˆ‘们å‘çŽîC¸»é¢æ¿ä¸‹æ–¹æœ‰ä¸‰ä¸ªTabåQŒåˆ†åˆ«äØ“ BrowseåQŒConfigurationå’ŒMirrorsåQŒæˆ‘们点击Configuration˜q›è¡Œé…ç½®åQŒä½ 现在需è¦å…³å¿ƒçš„æ˜¯ä¸¤ä¸ªé…¾|? ™å¹ï¼šâ€œRemote Storage Locationâ€äØ“˜qœç¨‹ä»“库的地å€åQŒå¯¹äºŽMaven Centralæ¥è¯´æ˜¯http://repo1.maven.org/maven2/åQ›â€œDownload Remote Indexesâ€é¡¾åæ€ä¹‰æ˜¯æŒ‡æ˜¯å¦ä¸‹è²˜qœç¨‹ç´¢å¼•æ–‡äšgåQŒMaven Centralçš„è¯¥å—æ®µé»˜è®¤ä¸ºFalseåQŒè¿™æ˜¯äؓ了防æ¢å¤§é‡Nexusæ— æ„识的åŽÀL¶ˆè€—ä¸å¤®ä»“库的带宽åQˆä¸å¤®ä»“库有大é‡çš„æž„ä»Óž¼Œå…¶çƒ¦å¼•文件也很大åQ‰ã€‚这里我 们需è¦å°†å…¶è®¾¾|®äØ“TrueåQŒç„¶åŽç‚¹å‡»Save。在Nexus下è²çš„ä¸å¤®ä»“库烦引文件之åŽï¼Œæˆ‘们ž®±å¯ä»¥åœ¨æœ¬åœ°æœçƒ¦ä¸å¤®ä»“库的所有构件。下囑ֱ•½CÞZº†æˆ‘ä»¬åˆšæ‰æ‰€ 涉åŠçš„é…¾|®ï¼š
Â
˜q™é‡Œæˆ‘们å†ä‹D一个例å,我们惌™¦ä»£ç†Sonatype的公å…׃»“库,其地å€ä¸ºï¼šhttp://repository.sonatype.org /content/groups/public/。æ¥éª¤å¦‚下,在Repositories颿¿çš„上方,点击AddåQŒç„¶åŽé€‰æ‹©Proxy RepositoryåQŒåœ¨ä¸‹æ–¹çš„é…¾|®éƒ¨åˆ†ï¼Œæˆ‘们填写如下的信æ¯ï¼šRepository ID - sonatypeåQ›Repository Name - Sonatype RepositoryåQ›Remote Storage Location - http://repository.sonatype.org/content/groups/public/ã€‚å…¶ä½™çš„ä¿æŒé»˜è®¤å€û|¼Œéœ€è¦æ³¨æ„çš„æ˜? Repository PolicyåQŒæˆ‘们䏿ƒ³ä»£ç†snapshotæž„äšgåQŒåŽŸå› å‰é¢å·²¾læ˜q°ã€‚ç„¶åŽç‚¹å‡»Save。酾|®é¡µé¢å¦‚下:
Â
Nexus预定义了3个本åœîC»“库,分别为ReleasesåQŒSnapshotsåQŒå’Œ3rd Party。这三个仓库都有å„自明确的目的。Releases用于部çÖv我们自己的releaseæž„äšgåQŒSnapshots用于部çÖv我们自己çš? snapshotæž„äšgåQŒè€?rd Party用于部çÖv½W¬ä¸‰æ–ÒŽž„ä»Óž¼Œæœ‰äº›æž„äšg如Oracleçš„JDBC驱动åQŒæˆ‘们ä¸èƒ½ä»Žå…¬å…±ä»“库下è²åˆŽÍ¼Œæˆ‘们ž®±éœ€è¦å°†å…‰™ƒ¨¾|²åˆ°è‡ªå·±çš„仓库ä¸ã€?/p>
å½“ç„¶ä½ ä¹Ÿå¯ä»¥åˆ›å¾è‡ªå·±çš„æœ¬åœîC»“库,æ¥éª¤å’Œåˆ›å»ÞZ»£ç†ä»“库类ä¼û|¼Œç‚¹å‡»Repository颿¿ä¸Šæ–¹çš„Add按钮åQŒç„¶åŽé€‰æ‹©Hosted RepositoryåQŒç„¶åŽåœ¨ä¸‹æ–¹çš„é…¾|®é¢æ¿ä¸è¾“å…¥idå’ŒnameåQŒæ³¨æ„这里我们ä¸å†éœ€è¦å¡«å†™è¿œ½E‹ä»“库地å€åQŒRepository Typeåˆ™äØ“ä¸å¯ä¿®æ”¹çš„hostedåQŒè€Œå…³äºŽRepository PolicyåQŒä½ å¯ä»¥æ ÒŽ®è‡ªå·±çš„需è¦é€‰æ‹©Release或者SnapshotåQŒå¦‚图:
Â
Nexusä¸ä»“库组的概忉|˜¯Maven没有的,在Maven看æ¥åQŒä¸½Ž¡ä½ 是hosted也好åQŒproxy也好åQŒæˆ–者group也好åQŒå¯¹æˆ‘都是一æ ? çš„ï¼Œæˆ‘åª½Ž¡æ ¹æ®groupIdåQŒartifactIdåQŒversion½{‰ä¿¡æ¯å‘ä½ è¦æž„äšgã€‚äØ“äº†æ–¹ä¾¿Maven的酾|®ï¼ŒNexus能够ž®†å¤šä¸ªä»“ 库,hosted或者proxyåˆåƈæˆä¸€ä¸ªgroupåQŒè¿™æ øP¼ŒMavenåªéœ€è¦ä¾èµ–于一个groupåQŒä¾¿èƒ½ä‹É用所有该group包å«çš„仓库的内容ã€?/p>
Nexus预定义了“Public Repositoriesâ€å’Œâ€œPublic Snapshot Repositoriesâ€ä¸¤ä¸ªä»“库组åQŒå‰è€…默认åˆòq¶æ‰€æœ‰é¢„定义的Release仓库åQŒåŽè€…默认åˆòq¶æ‰€æœ‰é¢„定义的Snapshot仓库。我们在本文å‰é¢çš? 部分创å¾äº†ä¸€ä¸ªå为“Sonatype Repositoryâ€çš„仓库åQŒçŽ°åœ¨å°†å…¶åˆòq¶åˆ°â€œPublic Repositoriesâ€ä¸ã€?/p>
点击仓库列表ä¸çš„“Public Repositoriesâ€ï¼Œç„¶åŽé€‰æ‹©ä¸‹æ–¹çš?Configuration" TabåQŒåœ¨é…ç½®é¢æ¿ä¸ï¼Œž®†å³è¾¹â€œAvaiable Repositoriesâ€ä¸çš„“Sonatype Repositoryâ€æ‹–拽到左边的“Ordered Group Repositoryâ€ä¸åQŒå¦‚图:
创å¾ä»“库¾l„和创å¾proxyåŠhosted仓库¾cÖM¼¼åQŒè¿™é‡Œä¸å†èµ˜˜q°ã€‚éœ€è¦æ³¨æ„的是formatå—æ®µéœ€è¦å¡«å†™â€œmaven2â€ï¼Œæ·ÕdŠ ä½ æ„Ÿå…´è¶£çš„ä»“åº“å³å¯ã€?/p>
Â
在浩大的Maven仓库ä¸ä¸€ä¸‹ä¸‹ç‚¹å‡»é“¾æŽ¥åQŒæµè§ˆèµ\径以å¯ÀL‰¾æ„Ÿå…´‘£çš„æž„äšg是一件很éƒé—·çš„事情。NexusåŸÞZºŽnexus-indexeræä¾›æž„äšgæœçƒ¦ 功能åQŒè¦æƒ›_¯¹ä»“库˜q›è¡Œæœçƒ¦åQŒæ— 论是hostedåQŒproxyåQŒæˆ–者groupåQŒä½ 都必™åÈ¡®è®¤çƒ¦å¼•文件å˜åœ¨ã€‚这一点对于代ç†ä»“库尤光™‡è¦ï¼Œæœ‰äº›˜qœç¨‹ä»“库å¯èƒ½ æ ÒŽœ¬ž®±æ²¡æœ‰çƒ¦å¼•ï¼Œæ‰€ä»¥ä½ æ— æ³•æœçƒ¦˜q™äº›ä»£ç†ä»“库。有些远½E‹ä»“库的˜qœç¨‹ç´¢å¼•éžå¸¸å¤§ï¼Œå¦‚ä¸å¤®ä»“库达åˆîCº†70Må·¦å³åQŒé‚£ä¹ˆç¬¬ä¸€‹Æ¡ä¸‹è½½çƒ¦å¼•需è¦èŠ±å¾ˆå¤šæ—‰™—´åQŒæ‰€ä»¥è¦æœ? 望得到æœç´¢ç»“果,¼‹®ä¿çœ‹åˆ°å¦‚下的文ä»Óž¼š
ä¸€æ—¦ä½ çš„Nexus拥有了本地或者远½E‹ä»“库的索引文äšgåQŒä½ ž®±å¯ä»¥äínå—Nexus的构件æœç´¢åŠŸèƒ½äº†ã€‚ä¸è®ºç™»é™†ä¸Žå¦ï¼Œä½ 都å¯ä»¥ä½¿ç”¨å…³é”®å—进行模¾pŠæœç´¢ï¼Œ æ¯”å¦‚æˆ‘åœ¨å·¦è¾¹å¯ÆDˆªæ 上部的æœçƒ¦æ¡†å†…输入junitåQŒç„¶åŽç‚¹å‡ÀLœç´¢æŒ‰é’®ï¼ŒåŒ™¾¹ç«‹åˆ»ä¼šåˆ†™å‰|˜¾½C?00多æ¡çš„junit相关构äšgä¿¡æ¯ã€‚å¦‚æžœä½ äº†è§£æ›´å¤šçš„ä¿¡æ¯ï¼Œä½? 也å¯ä»¥é€šè¿‡é™å®šgroupIdåQŒartifactIdåQŒversion˜q›è¡Œæœçƒ¦åQŒç‚¹å‡Õd¯¼èˆªæ ä¸çš„“Advanced Searchâ€ï¼Œç‚¹å‡»åŒ™¾¹æ‰€æœ‰é¡µé¢å·¦ä¸Šè§’的下拉框åQŒé€‰æ‹©â€œGAV Searchâ€ã€‚笔者这里输入junit:junit:4.4åQŒç„¶åŽå›žè½¦ï¼š
选择一™åÒŽœç´¢ç»“果,在页é¢ä¸‹æ–¹ä¼šæ˜„¡¤ºâ€œArtifact Informationâ€çš„颿¿åQŒä½ å¯ä»¥ç‚¹å‡»"artifact"或è€?pom"下è²å¯¹åº”æ–‡äšgåQŒè€Œè¯¥é¢æ¿åŒ™¾¹æ›´æ˜¾½CÞZº†ä¸€ä¸ªMavenä¾èµ–é…ç½®åQŒä½ å¯ä»¥ç›´æŽ¥å¤åˆ¶è¯¥é…¾|®åˆ°Maven POMä¸ï¼Œ˜q™æ˜¯ä¸ªå分方便的ç‰ÒŽ€§ã€?/p>
æ¤å¤–åQŒå€¼å¾—一æçš„æ˜¯ï¼ŒNexus˜q˜æ”¯æŒåŸºäºŽclassnameçš„æœç´¢ï¼Œä½ åªéœ€ç‚¹å‡»æœçƒ¦™åµé¢å³ä¸Šè§’的下拉框,选择“Classname Searchâ€ï¼Œç„¶åŽè¾“å…¥¾cÕdå›_¯åQŒè¿™é‡Œæˆ‘ä¸å†èµ˜è¿°ã€?/p>
Â
默认情况下,Mavenä¾èµ–于ä¸å¤®ä»“库,˜q™æ˜¯ä¸ÞZº†èƒ½è®©Mavenå¼€½Ž±å³ç”¨ï¼Œä½†ä»…ä»…è¿™ä¹ˆåšæ˜Žæ˜¾æ˜¯é”™è¯¯çš„åQŒè¿™ä¼šé€ æˆå¤§é‡çš„æ—¶é—´åŠå¸¦å®½çš„æµªè´V€‚æ—¢ç„¶æ–‡ç« çš„å‰é¢å·²ç»ä»‹ç»äº†å¦‚何安装和é…ç½®NexusåQŒçŽ°åœ¨æˆ‘ä»¬å°±è¦é…¾|®Mavenæ¥ä‹É用本地的NexusåQŒä»¥èŠ‚çœæ—‰™—´å’Œå¸¦å®½èµ„æºã€?/p>
我们å¯ä»¥ž®†Repositoryé…置到POMä¸ï¼Œä½†ä¸€èˆ¬æ¥è¯´è¿™ä¸æ˜¯å¾ˆå¥½çš„åšæ³•ï¼ŒåŽŸå› å¾ˆç®€å•ï¼Œä½ éœ€è¦äؓ所有的Maven™å¹ç›®é‡å¤è¯¥é…¾|®ã€‚å› æ¤ï¼Œ˜q™é‡Œæˆ‘å°†Repository的酾|®æ”¾åˆ?user_home/.m2/settings.xmlä¸ï¼š
ç”׃ºŽæˆ‘们ä¸èƒ½ç›´æŽ¥åœ¨settings.xml䏿’å…?lt;repositories>å…ƒç´ åQŒè¿™é‡Œæˆ‘们编写了一个profileåQŒåƈæ·ÕdŠ äº†ä¸€ 个profileòq¶ä‹Éç”?lt;activeProfile>å…ƒç´ è‡ªåŠ¨ž®†è¿™ä¸ªprofile‹È€‹z…R€‚这里的local-nexus仓库指å‘äº†åˆšæ‰æˆ‘ä»? é…置的Nexusä¸â€œPublic Repositoriesâ€ä»“库组åQŒä¹Ÿž®±æ˜¯è¯ß_¼Œæ‰€æœ‰è¯¥ä»“库¾l„包å«çš„仓库都能供我们ä‹É用。æ¤å¤–,我们通过<releases> å’?lt;snapshots>å…ƒç´ ‹È€‹zÖMº†Maven对于仓库所有类型构件下载的支æŒåQŒå½“ç„¶ä½ ä¹Ÿå¯ä»¥è°ƒèŠ‚è¯¥é…ç½®åQŒæ¯”如说¼›æ¢Maven从Nexus 下è²snapshotæž„äšgã€?/p>
使用该酾|®ï¼ŒMavenž®×ƒ¼šä»Žä½ çš„NexusæœåŠ¡å™¨ä¸‹è½½æž„ä»¶äº†åQŒé€Ÿåº¦å’Œä»ŽCentral下è²å¯ä¸æ˜¯ä¸€ä¸ªæ•°é‡çñ”çš„ã€?/p>
Â
Nexusæä¾›äº†ä¸¤¿Uæ–¹å¼æ¥éƒ¨çÖvæž„äšgåQŒä½ å¯ä»¥ä»ŽUIç›´æŽ¥ä¸Šä¼ åQŒä¹Ÿå¯ä»¥é…ç½®Maven部çÖvæž„äšgã€?/p>
Â
有时候有个jaræ–‡äšgä½ æ— æ³•ä»Žå…¬å…±Maven仓库扑ֈ°åQŒä½†æ˜¯ä½ 能从其它得到˜q™ä¸ªjaræ–‡äšgåQˆç”šè‡Ïx˜¯POMåQ‰ï¼Œé‚£ä¹ˆä½ 完全å¯ä»¥å°†˜q™ä¸ªæ–‡äšg部çÖv到Nexusä¸ï¼Œä½¿å…¶æˆäØ“æ ‡å‡†‹¹ç¨‹çš„一部分。æ¥éª¤å¦‚下:
ç‚¹å‡»å·¦è¾¹å¯ÆDˆªæ çš„"Repository"åQŒåœ¨åŒ™¾¹çš„仓库列表ä¸é€‰æ‹©ä¸€ä¸ªä»“库,如â€?rd Partyâ€ï¼Œç„¶åŽä¼šçœ‹åˆ°é¡µé¢ä¸‹æ–ÒŽœ‰å››ä¸ªtabåQŒé€‰æ‹©æœ€åŽä¸€ä¸ªâ€œUploadâ€ï¼Œä½ 会看到构äšgä¸Šä¼ ç•Œé¢ã€‚é€‰æ‹©ä½ è¦ä¸Šä¼ 的构ä»Óž¼Œòq¶æŒ‡å®šPOMåQŒï¼ˆæˆ–者手工编 写GAV½{‰ä¿¡æ¯ï¼‰åQŒæœ€åŽç‚¹å‡»UploadåQŒè¯¥æž„äšgž®Þq›´æŽ¥è¢«éƒ¨çÖvåˆîCº†Nexusçš?3rd Party"仓库ä¸ã€‚如图:
更常è§çš„用例是:团队在开å‘一个项目的å„个模å—åQŒäؓ了让自己开å‘的模å—能够快速让其他äºÞZ‹Éç”¨ï¼Œä½ ä¼šæƒŒ™¦ž®†snapshot版本的构仉™ƒ¨¾|²åˆ°Maven仓库ä¸ï¼Œå…¶ä»–人åªéœ€è¦åœ¨POMæ·ÕdŠ ä¸€ä¸ªå¯¹äºŽä½ å¼€å‘æ¨¡å—çš„ä¾èµ–åQŒå°±èƒ½éšæ—¶æ‹¿åˆ°æœ€æ–°çš„snapshotã€?/p>
以下的pom.xmlé…置和settings.xmlèƒ½è®©ä½ é€šè¿‡Maven自动化部¾|²æž„ä»Óž¼š
pom.xml
settings.xml
˜q™é‡Œæˆ‘们é…置所有的snapshot版本构äšg部çÖv到Nexusçš„Snapshots仓库ä¸ï¼Œ 所有的releaseæž„äšg部çÖv到Nexusçš„Releases仓库ä¸ã€‚由于部¾|²éœ€è¦ç™»é™†ï¼Œå› äØ“æˆ‘ä»¬åœ¨settings.xmlä¸é…¾|®å¯¹åº? Repository id的用户å和密ç ã€?/p>
ç„¶åŽåQŒåœ¨™å¹ç›®ç›®å½•䏿‰§è¡?strong>mvn deploy åQŒä½ 会看到mavenž®†é¡¹ç›®æž„仉™ƒ¨¾|²åˆ°Nexusä¸ï¼Œ‹¹è§ˆNexus对应的仓库,ž®±å¯ä»¥çœ‹åˆ°åˆšæ‰éƒ¨¾|²çš„æž„äšg。当其他人构建其™å¹ç›®æ—Óž¼ŒMavenž®×ƒ¼šä»ŽNexuså¯ÀL‰¾ä¾èµ–òq¶ä¸‹è½½ã€?/p>
Â
本文介ç»å¼ºå¤§çš„仓库管ç†å™¨â€”—NexusåQŒåŒ…括如何下载安装NexusåQŒé…¾|®Nexus代ç†ä¸å¤®ä»“库åQŒç®¡ç†Nexus的代ç†ä»“库,本地仓库åQŒä»¥åŠä»“ åº“ç»„ã€‚åÆˆå¸®åŠ©ä½ äº†è§£å¦‚ä½•é€šè¿‡Nexusæœçƒ¦æž„äšg。最åŽï¼Œå¦‚何在Mavenä¸é…¾|®Nexus仓库åQŒä»¥åŠå¦‚何部¾|²æž„件到Nexus仓库ä¸ã€‚这些都是Nexus 䏿œ€åŸºæœ¬ä¹Ÿæ˜¯æœ€å¸¸ç”¨çš„功能。éšç€ä½¿ç”¨çš„æ·±å…¥ï¼Œä½ 会å‘现Nexus˜q˜æœ‰å¾ˆå¤šå…¶å®ƒçš„特性,如用æˆïL®¡ç†ï¼Œè§’色æƒé™½Ž¡ç†½{‰ç‰ã€?/p>
Nexusçš„OSS版本是完全开æºçš„åQŒå¦‚æžœä½ æœ‰å…´‘£ï¼Œä½ å¯ä»¥å¦ä¹ å…¶æºç åQŒç”šè‡Œ™‡ªå·±å®žçŽîC¸€ä¸ªREST客户端ã€?/p>
马上拥抱Nexuså§ï¼Œå®ƒæ˜¯å…费的ï¼
   http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 | 1. User Level. This settings.xml file provides configuration for a single user,
 |                and is normally provided in $HOME/.m2/settings.xml.
 |
 |                NOTE: This location can be overridden with the system property:
 |
 |                -Dorg.apache.maven.user-settings=/path/to/user/settings.xml
 |
 | 2. Global Level. This settings.xml file provides configuration for all maven
 |                users on a machine (assuming they're all using the same maven
 |                installation). It's normally provided in
 |                ${maven.home}/conf/settings.xml.
 |
 |                NOTE: This location can be overridden with the system property:
 |
 |                -Dorg.apache.maven.global-settings=/path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings>
 <localRepository>D:/maven-2.0.9/repository</localRepository>
 <!-- interactiveMode
  | This will determine whether maven prompts you when it needs input. If set to false,
  | maven will use a sensible default value, perhaps based on some other setting, for
  | the parameter in question.
  |
  | Default: true
 <interactiveMode>true</interactiveMode>
 -->
 <!-- offline
  | Determines whether maven should attempt to connect to the network when executing a build.
  | This will have an effect on artifact downloads, artifact deployment, and others.
  |
  | Default: false
 <offline>false</offline>
 -->
 <!-- proxies
  | This is a list of proxies which can be used on this machine to connect to the network.
  | Unless otherwise specified (by system property or command-line switch), the first proxy
  | specification in this list marked as active will be used.
  |-->
 <proxies>
   <!-- proxy
    | Specification for one proxy, to be used in connecting to the network.
    |
   <proxy>
     <id>optional</id>
     <active>true</active>
     <protocol>http</protocol>
     <username>proxyuser</username>
     <password>proxypass</password>
     <host>proxy.host.net</host>
     <port>80</port>
     <nonProxyHosts>local.net,some.host.com</nonProxyHosts>
   </proxy>
   -->
 </proxies>
 <!-- servers
  | This is a list of authentication profiles, keyed by the server-id used within the system.
  | Authentication profiles can be used whenever maven must make a connection to a remote server.
  |-->
 <servers>
   <!-- server
    | Specifies the authentication information to use when connecting to a particular server, identified by
    | a unique name within the system (referred to by the 'id' attribute below).
    |
    | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
    |      used together.
    |
   <server>
     <id>deploymentRepo</id>
     <username>repouser</username>
     <password>repopwd</password>
   </server>
   -->
  Â
   <!-- Another sample, using keys to authenticate.
   <server>
     <id>siteServer</id>
     <privateKey>/path/to/private/key</privateKey>
     <passphrase>optional; leave empty if not used.</passphrase>
   </server>
   -->
 <server>
     <id>nexus</id>
     <username>admin</username>
     <password>admin123</password>
   </server>
 </servers>
 <!-- mirrors
  | This is a list of mirrors to be used in downloading artifacts from remote repositories.
  |
  | It works like this: a POM may declare a repository to use in resolving certain artifacts.
  | However, this repository may have problems with heavy traffic at times, so people have mirrored
  | it to several places.
  |
  | That repository definition will have a unique id, so we can create a mirror reference for that
  | repository, to be used as an alternate download site. The mirror site will be the preferred
  | server for that repository.
  |-->
 <mirrors>
   <!-- mirror
    | Specifies a repository mirror site to use instead of a given repository. The repository 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 the set 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>nexus</id>         Â
     <name>Maven Repository Manager running on http://125.76.229.146:8080/nexus</name>
     <url>http://125.76.229.146:8080/nexus/content/groups/public</url>
     <mirrorOf>*</mirrorOf>
   </mirror>
 </mirrors>
Â
 <!-- profiles
  | This is a list of profiles which can be activated in a variety of ways, and which can modify
  | the build process. Profiles provided in the settings.xml are intended to provide local machine-
  | specific paths and repository locations which allow the build to work in the local environment.
  |
  | For example, if you have an integration testing plugin - like cactus - that needs to know where
  | your Tomcat instance is installed, you can provide a variable here such that the variable is
  | dereferenced during the build process to configure the cactus plugin.
  |
  | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
  | section of this document (settings.xml) - will be discussed later. Another way essentially
  | relies on the detection of a system property, either matching a particular value for the property,
  | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
  | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
  | Finally, the list of active profiles can be specified directly from the command line.
  |
  | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
  |      repositories, plugin repositories, and free-form properties to be used as configuration
  |      variables for plugins in the POM.
  |
  |-->
 <profiles>
   <!-- profile
    | Specifies a set of introductions to the build process, to be activated using one or more of the
    | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
    | or the command line, profiles have to have an ID that is unique.
    |
    | An encouraged best practice for profile identification is to use a consistent naming convention
    | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
    | This will make it more intuitive to understand what the set of introduced profiles is attempting
    | to accomplish, particularly when you only have a list of profile id's for debug.
    |
    | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
   <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>
   -->
   <!--
    | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
    | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
    | might hypothetically look like:
    |
    | ...
    | <plugin>
    |  <groupId>org.myco.myplugins</groupId>
    |  <artifactId>myplugin</artifactId>
    | Â
    |  <configuration>
    |    <tomcatLocation>${tomcatPath}</tomcatLocation>
    |  </configuration>
    | </plugin>
    | ...
    |
    | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
    |      anything, you could just leave off the <value/> inside the activation-property.
    |
   <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>
 <!-- activeProfiles
  | List of profiles that are active for all builds.
  |
 <activeProfiles>
   <activeProfile>alwaysActiveProfile</activeProfile>
   <activeProfile>anotherAlwaysActiveProfile</activeProfile>
 </activeProfiles>
 -->
</settings>