Terry.Li-彬

          虛其心,可解天下之問;專其心,可治天下之學(xué);靜其心,可悟天下之理;恒其心,可成天下之業(yè)。

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            143 隨筆 :: 344 文章 :: 130 評論 :: 0 Trackbacks
          maven2
              相信maven1 大家都已經(jīng)很熟悉了,具體maven能做什,就不詳細(xì)說了。個(gè)人得maven在項(xiàng)目中用的是比多的,公司內(nèi)部,就不太清楚了。我以前的公司用一段時(shí)間,不后來就沒有下文了。
              與maven1 相比,maven2可算是幾乎重寫了,不
          從速度來說應(yīng)該更快。
             
          主要的幾個(gè)新特性包括:(詳細(xì)參考http://www.ibm.com/developerworks/cn/opensource/os-maven2/index.html
              1
          . 更快、更簡單
                 
          速度方面可以比上ant
              2
          . 更少的配置文件
                 
          現(xiàn)在的配置文件只剩下了settings.xmlpom.xml了。
             
          3.  Plugin言更
                 
          始支持java,BeanShell和ant
              4.  提供了
          預(yù)的模版
                 
          點(diǎn)是最有幫助的,用可以自己定自己的項(xiàng)目模版了,就像用appfuse一生成項(xiàng)結(jié)構(gòu)
              5. 生命周期的引入
                   在Maven2中有了明確的生命周期概念,而且都提供與之
          對應(yīng)的命令,使得項(xiàng)目構(gòu)建更加清晰明了。
             
          6.  新增Dependency Scope    
                  
          點(diǎn)也比重要,有些用于test的包,可以不用加入依
              7. 
          傳遞化依管理
                 
          是最方便的,可以省了很多配置。如a 依 b,b 認(rèn) a也會(huì)依 c。但是也會(huì)患,如版本沖突。不maven 也已經(jīng)到了,可以使用exclusions來排除相應(yīng)的重復(fù)

          了那多,現(xiàn)在切入正始maven2 之旅:
          首些下需要的工具:
          maven2: http://maven.apache.org/download.html 最主要的
          maven-proxy:用來代理repository,使用本地
          代替maven2的遠(yuǎn)
                      http://maven-proxy.codehaus.org/
          continuum
          :一個(gè)不錯(cuò)的持續(xù)整合工具,用于自動(dòng)build。支持ant,maven
          http://maven.apache.org/continuum/
          svn:版本控制工具相信都已
          經(jīng)配置了。
          maven 用于eclipse的插件 ,maven主站有下,不錯(cuò)的插件。當(dāng)然idea也有相應(yīng)的插件
          最后,http,服務(wù)器是必不可少的。用于內(nèi)部開發(fā)使用。
          可以使用apache ,或者jetty  http://www.mortbay.org/

          安裝:
             
          安裝maven2簡單,把下來的maven包解就行了。(目前我的配置都在win2003上,沒有應(yīng)用于linux,所有所有的配置都針對 windows).增加相應(yīng)環(huán)m2_home=maven2的安裝目,不要忘了設(shè)java_home的目。另外在path中增加% m2_home%\bin;可以直接在命令行下面使用mvn
          其他工具的安裝在后續(xù)的文章會(huì)介

          始第一個(gè)mvean2項(xiàng)目:
            mvn archetype:create -DgroupId=com.mycompany.app \
                             -DartifactId=my-app
           
          簡單一下 groupId相當(dāng)于你的組織,如同org.springframework,會(huì)轉(zhuǎn)應(yīng)得本地路徑 artifactId,你主要的jar包名稱,也就是你要打成的jar 名稱。
          編譯應(yīng)
              mvn compile
                 
          編譯應(yīng)jave 文件
          編譯測試類以及運(yùn)行測試類
              mvn test
                
          運(yùn)行測試類
          如果只想編譯test執(zhí)
              mvn test-compile
          打包和安裝你的本地
          打包:
              mvn package
          安裝:
              mvn install
          創(chuàng)web site
              mvn site
          清除所有
              mvn clean
          創(chuàng)建相關(guān)ide文件
              mvn idea:idea       
          或者    mvn eclipse:eclipse

             
          便一下,maven2 是有生命周期一概念的,也就是如果你執(zhí)package,相應(yīng)的以前步驟,如compile,test等都會(huì)自動(dòng)執(zhí)行。
          剛開執(zhí)行會(huì)比慢,需要從maven2遠(yuǎn)中下所有的文件到本地。如果你的本地沒有相應(yīng)的依包,則每次maven都會(huì)去遠(yuǎn)程下,所以配置一個(gè)就比重要了。
             
          另外介一下主要的參考料:
              mavn2
          主站:主要的pomsettings.xml參考
              Better Builds with Maven     http://www.mergere.com/m2book_download.jsp
             
          錯(cuò),主要通例子介可惜都是E文的,花點(diǎn)時(shí)間還得的。
              下一個(gè)主
          ,會(huì)一下maven2的主要配置。

           
           
          maven 配置篇 之 settings.xml
              maven2 比起maven1 ,需要配置的文件少多了,主要集中在pom.xmlsettings.xml中。
             
          先來說說settings.xmlsettings.xmlmaven相當(dāng)于全局性的配置,用于所有的項(xiàng)目。在maven2中存在兩個(gè) settings.xml,一個(gè)位于maven2的安裝目conf下面,作全局性配置。團(tuán)隊(duì)設(shè)置,保持一致的定關(guān)鍵,所以 maven2/conf下面的settings.xml就作為團(tuán)隊(duì)共同的配置文件。保所有的團(tuán)隊(duì)有相同的配置。當(dāng)然個(gè)成,都需要特殊的 自定義設(shè)置,如用信息,所以另外一個(gè)settings.xml就作本地配置。默認(rèn)的位置:${user.dir} /.m2/settings.xml目中(${user.dir} 指windows 中的用)。
              settings.xml基本
          結(jié)構(gòu)如下:
              <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>
          簡單一下幾個(gè)主要的配置因素:
          localRepository表示本地
          的保存位置,也就是maven2主要的jar保存位置,默認(rèn)在${user.dir}/.m2/repository,如果需要另外設(shè)置,就成其他的路徑。
          offline如果不想
          編譯,都去遠(yuǎn)程中心,那就設(shè)true。當(dāng)然前提是你已經(jīng)了必的依包。
          Servers
             在POM中的 distributionManagement元素定
          開發(fā)庫。然而,特定的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,用于匹配distributionManagementid,比重要。
          • username, password:用于登此服務(wù)器的用名和密
          • privateKey, passphrase設(shè)private key,以及passphrase
          • filePermissions, directoryPermissions:當(dāng)文件或者目錄創(chuàng)建后,需要使用權(quán)進(jìn)訪問。參照unix文件可,如664775
          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:唯一的標(biāo)志,用于區(qū)別鏡
          • url:像的url
          • mirrorOf:此像指向的服務(wù)id
          Proxies
          設(shè)置,主要用于無法直接訪問中心的配置。
           
          <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:代理的標(biāo)
          • active:是否激活代理
          • protocol, host, port:protocol://host:port 代理
          • username, password:用名和密
          • nonProxyHosts: 不需要代理的host
          Profiles
           
          似于pom.xml中的profile元素,主要包括activation,repositories,pluginRepositories properties元素
           
          剛開始接觸的時(shí)候,可能會(huì)比迷惑,其實(shí)這maven2中比較強(qiáng)大的功能。從字面上來,就是個(gè)性配置。
           
          獨(dú)定profile后,并不會(huì)生效,需要通過滿足條件來激活。
           
          repositories pluginRepositories
           
          其他開發(fā)庫和插件開發(fā)庫團(tuán)隊(duì),肯定有自己的開發(fā)庫。可以通此配置來定
           
          如下的配置,定了本地開發(fā)庫,用于release 發(fā)布。
              <repositories>
                  <repository>
                    <id>repo-local</id>
                 <name>Internal
          開發(fā)庫</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
          開發(fā)庫</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:
          個(gè)產(chǎn)品的版本的Release或者snapshot(注:releasesnapshot的區(qū)release一般是比較穩(wěn)定的版本,而snapshot基本上不穩(wěn)定,只是作快照)

          properties
            maven
          propertiesplaceholder,如antproperties
          包括以下的5種類
          1.        env.X,返回當(dāng)前的環(huán)
          2.        project.x:返回pom中定的元素,如project.version
          3.        settings.x:返回settings.xml中定的元素
          4.        java 統(tǒng)屬性:所有經(jīng)過java.lang.System.getProperties()返回的
          5.        x:用自己設(shè)定的
          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版本,將會(huì)激活
          • os:操作系統(tǒng)
          • property:如果maven檢測到相應(yīng)的屬性
          • file: 用于判斷文件是否存在或者不存在

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

           
           
          maven 配置篇 之pom.xml
              完了settings.xml配置,下來一下maven2的主要配置pom.xml
          pom?
             
          pom為項(xiàng)象模型。通xml表示maven項(xiàng)目,使用pom.xml來實(shí)現(xiàn)。主要描述了項(xiàng)目:包括配置文件;開發(fā)者需要遵循的規(guī)則,缺陷管理系統(tǒng)組織和licenses,項(xiàng)目的url,項(xiàng)目的依性,以及其他所有的項(xiàng)目相關(guān)因素。
          快速察看:
          <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>

          基本內(nèi)容:
              POM
          包括了所有的項(xiàng)目信息。
          maven
          關(guān)
          pom
          了最小的maven2元素,允groupId,artifactId,version。所有需要的元素
          • groupId:項(xiàng)目或者組織的唯一標(biāo)志,并且配置時(shí)生成的路徑也是由此生成,如org.codehaus.mojo生成的相路徑/org/codehaus/mojo
          • artifactId: 項(xiàng)目的通用名稱
          • version:項(xiàng)目的版本
          • packaging: 打包的機(jī)制,如pom, jar, maven-plugin, ejb, war, ear, rar, par
          • classifier:
          POM關(guān)系:
          主要承,合成
           
          賴關(guān)系:
            <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:描述了依項(xiàng)目唯一標(biāo)
          可以通以下方式進(jìn)行安裝:
          ·   使用以下的命令安裝:
          ·   mvn install:install-file –Dfile=non-maven-proj.jar –DgroupId=some.group –DartifactId=non-maven-proj –Dversion=1
          ·   創(chuàng)建自己的,并配置,使用deploy:deploy-file
          ·   設(shè)置此依圍為system,定一個(gè)系統(tǒng)路徑。不提倡。
          • type:應(yīng)的依賴產(chǎn)品包形式,如jarwar
          • scope:用于限制相應(yīng)的依,包括以下的幾種變量:
          ·   compile :默認(rèn),用于編譯
          ·   provided似于編譯,但支持你期待jdk或者容器提供,似于classpath
          ·   runtime:執(zhí)時(shí),需要使用
          ·   test:用于test務(wù)時(shí)使用
          ·   system:需要外在提供相應(yīng)得元素。通systemPath來取得
          • systemPath: 用于范圍為system。提供相應(yīng)的路徑
          • optional: 標(biāo)注可,當(dāng)項(xiàng)目自身也是依賴時(shí)。用于連續(xù)賴時(shí)使用
             獨(dú)占性    
            
          外在告maven你只包括指定的項(xiàng)目,不包括相關(guān)的依。此因素主要用于解決版本沖突問題
            <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>
          表示項(xiàng)目maven-embedder需要項(xiàng)目maven-core,但我不想引用maven-core

          關(guān)
             
          另一個(gè)強(qiáng)大的化,maven來的是項(xiàng)承。主要的設(shè)置:
          項(xiàng)
          <project>
            <modelVersion>4.0.0</modelVersion>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>my-parent</artifactId>
            <version>2.0</version>
            <packaging>pom</packaging>
          </project>
              packaging
          型,需要pom用于parent和合成多個(gè)項(xiàng)目。我需要增加相應(yīng)值給父pom,用于子項(xiàng)承。主要的元素如下:
          • 開發(fā)者和合作者
          • 插件列表
          • 報(bào)表列表
          • 插件執(zhí)行使用相應(yīng)的匹配ids
          • 插件配置
          • 項(xiàng)目配置
          <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的目,用于快速查詢

          dependencyManagement

          用于父項(xiàng)目配置共同的依賴關(guān)系,主要配置依包相同因素,如版本,scope

          合成(或者多個(gè)模
             
          一個(gè)項(xiàng)目有多個(gè)模,也叫做多重模,或者合成項(xiàng)目。
          如下的定
          <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
          設(shè)
             
          主要用于編譯設(shè)置,包括兩個(gè)主要的元素,buildreport
            build
             
          主要分兩部分,基本元素和擴(kuò)展元素集合
          注意:包括項(xiàng)buildprofile 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: 認(rèn)的目標(biāo)或者段。如install
          • directory: 編譯輸出的目
          • finalName: 生成最后的文件的
          • filter: 義過濾,用于替應(yīng)的屬性文件,使用maven定的屬性。設(shè)置所有placehold

          (resources)
             
          項(xiàng)目中需要指定的源。如spring配置文件,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: 指定目標(biāo)路徑,用于放置源,用于build
          • filtering: 是否替換資源中的屬性placehold
          • directory: 源所在的位置
          • includes: 式,包括那些
          • excludes: 排除的
          • testResources: 測試資源列表
          插件
           
          build時(shí)執(zhí)行的插件,比有用的部分,如使用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,是否裝插件擴(kuò)展。默認(rèn)false
          • inherited: true or false,是否此插件配置將會(huì)應(yīng)用于poms,那些承于此的項(xiàng)
          • configuration: 指定插件配置
          • dependencies: 插件需要依的包
          • executions: 用于配置execution標(biāo),一個(gè)插件可以有多個(gè)目標(biāo)
          如下:
              <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>
           
          明:
          • id:規(guī)execution 的唯一標(biāo)
          • goals: 表示目標(biāo)
          • phase: 表示段,目標(biāo)將會(huì)在什么階執(zhí)
          • inherited: 和上面的元素一設(shè)false maven將會(huì)拒絕執(zhí)子插件
          • configuration: 表示此執(zhí)行的配置屬性

          插件管理
              pluginManagement
          :插件管理以同的方式包括插件元素,用于在特定的項(xiàng)目中配置。所有承于此項(xiàng)目的子項(xiàng)目都能使用。主要定插件的共同元素

          擴(kuò)展元素集合
          主要包括以下的元素:
          Directories
          用于設(shè)置各錄結(jié)構(gòu),如下:
            <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

          表示需要擴(kuò)展的插件,必包括進(jìn)應(yīng)build路徑。

          <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報(bào)表。特定的maven 插件能出相應(yīng)的定制和配置報(bào)表。
            <reporting>
              <plugins>
                <plugin>
                  <outputDirectory>${basedir}/target/site</outputDirectory>
                  <artifactId>maven-project-info-reports-plugin</artifactId>
                  <reportSets>
                    <reportSet></reportSet>
                  </reportSets>
                </plugin>
              </plugins>
            </reporting>

          Report Sets
             
          用于配置不同的目標(biāo)應(yīng)用于不同的報(bào)
          <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>

          更多的項(xiàng)目信息
          name:
          項(xiàng)目除了artifactId外,可以定多個(gè)名稱
          description:
          項(xiàng)目描述
          url:
          項(xiàng)url
          inceptionYear:
          創(chuàng)始年份

          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>

          Organization
          配置組織信息
            <organization>
              <name>Codehaus Mojo</name>
              <url>http://mojo.codehaus.org</url>
            </organization>

          Developers
          配置開發(fā)者信息
          <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>

          環(huán)設(shè)

          Issue Management
             
          關(guān)bug跟蹤系統(tǒng),如bugzilla,testtrack,clearQuest
            <issueManagement>
              <system>Bugzilla</system>
              <url>http://127.0.0.1/bugzilla</url>
            </issueManagement>
          Continuous Integration Management
          連續(xù)整合管理,基于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
           
          件配置管理,如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中的開發(fā)庫

          Plugin Repositories
          配置同 repositories

          Distribution Management
          用于配置分發(fā)管理,配置相應(yīng)產(chǎn)發(fā)布信息,主要用于發(fā)布,在執(zhí)mvn deploy后表示要發(fā)布的位置
          1
          配置到文件系統(tǒng)
          <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配置
             
          編譯擴(kuò)展用于指定使用wagon外在ssh提供,用于提供你的文件到相應(yīng)遠(yuǎn)程服務(wù)器。
          <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
          對應(yīng)于你的開發(fā)庫,用信息通settings.xml中的server取得

          Profiles
          似于settings.xml中的profiles,增加了幾個(gè)元素,如下的式:
            <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>
           

           
           
          使用maven2 進(jìn)團(tuán)隊(duì)配置
              團(tuán)隊(duì),建立統(tǒng)一的開發(fā)環(huán)境是必的,而maven能很好幫助建立統(tǒng)一的環(huán)境。下面就介如何更有效的進(jìn)統(tǒng)一的配置。
          準(zhǔn)工作:
            
          件:
          maven2: http://maven.apache.org/download.html
          最主要的
          maven-proxy
          :用來代理repository,使用代理來訪問多個(gè)遠(yuǎn)
                      http://maven-proxy.codehaus.org/
          continuum
          :一個(gè)不錯(cuò)的持續(xù)整合工具,用于自動(dòng)build支持ant,maven
          http://maven.apache.org/continuum/
          svn:版本控制工具

          創(chuàng)建一致的開發(fā)環(huán)
            
             
          在共享的開發(fā)環(huán)境中,更好的建是保持maven的兩個(gè)不同的配置文件分管理,包括共享和用自定義設(shè)置。共同的配置包括在安裝目中,而獨(dú)的開發(fā)設(shè)置保存在用本地目
             
             
          全局的配置文件settings.xml
           
          <servers>
                 //
          公司內(nèi)部,所有的release版本,serverid對應(yīng)repository id,用于在deploy時(shí)訪問使用,主要保存用名和密
          <server>
          <id>internal</id>
          <username>${website.username}</username>
          <password>${website.pwd}</password>
          <filePermissions>664</filePermissions>
          <directoryPermissions>775</directoryPermissions>
          </server>
          //
          目前的開發(fā)庫,用于snapshot
          <server>
          <id>snapshot</id>
          <username>${website.username}</username>
          <password>${website.pwd}</password>
          <filePermissions>664</filePermissions>
          <directoryPermissions>775</directoryPermissions>
          </server>
          </servers>

          <profiles>
          <!--
          核心 maven ,maven-proxy實(shí)現(xiàn)-->
          <profile>
          <id>central-repo</id>
          <repositories>
          <repository>
          <id>central</id>
          <name>Internal Repository</name>
          <url>http://192.168.0.2:9999/repository</url>
          </repository>
          </repositories>
          <pluginRepositories>
          <pluginRepository>
          <id>central</id>
          <name>Internal Repository</name>
          <url>http://192.168.0.2:9999/repository</url>
          </pluginRepository>
          </pluginRepositories>
          </profile>

          <!--
          內(nèi)部,包括公司的所有release版本-->
          <profile>
          <id>internal-repo</id>
          <repositories>
          <repository>
          <id>internal</id>
          <name>Internal Repository</name>
          <url>http://192.168.0.2:8080/repo-local</url>
          <releases>
          <enabled>true</enabled>
          <updatePolicy>never</updatePolicy>
          <checksumPolicy>warn</checksumPolicy>
          </releases>
          </repository>
          </repositories>
          <pluginRepositories>
          <pluginRepository>
          <id>internal</id>
          <name>Internal Plugin Repository</name>
          <url>http://192.168.0.2:8080/repo-local</url>
          <releases>
          <enabled>true</enabled>
          <updatePolicy>never</updatePolicy>
          <checksumPolicy>warn</checksumPolicy>
          </releases>
          </pluginRepository>
          </pluginRepositories>
          </profile>
          <!--
          內(nèi)部開發(fā)庫 ,也可以合并snapshotrelease-->
          <profile>
          <id>snapshot-repo</id>
          <repositories>
          <repository>
          <id>snapshot</id>
          <name>Internal Repository</name>
          <url>http://192.168.0.2:8080/repo-snapshot</url>
          <snapshots>
          <enabled>true</enabled>
          <updatePolicy>interval:60</updatePolicy>
          <checksumPolicy>warn</checksumPolicy>
          </snapshots>
          </repository>
          </repositories>
          <pluginRepositories>
          <pluginRepository>
          <id>snapshot</id>
          <name>Internal Plugin Repository</name>
          <url>http://192.168.0.2:8080/repo-snapshot</url>
          <snapshots>
          <enabled>true</enabled>
          <updatePolicy>interval:60</updatePolicy>
          <checksumPolicy>warn</checksumPolicy>
          </snapshots>
          </pluginRepository>
          </pluginRepositories>
          </profile>
          </profiles>
          <!--
          激活相應(yīng)得配置-->
          <activeProfiles>
          <activeProfile>central-repo</activeProfile>
          <activeProfile>internal-repo</activeProfile>
          <activeProfile>snapshot-repo</activeProfile>
          </activeProfiles>
          <!--
          插件默認(rèn)groupId -->
          <pluginGroups>
          <pluginGroup>com.mycompany.plugins</pluginGroup>
          </pluginGroups>
           
          包括了以下的共享因素:
          務(wù)設(shè)置典型是共同的,只有用名需要在用戶環(huán)境中設(shè)置。使用一致的定來配置共同的設(shè)
          • profile了共同的因素,內(nèi)部開發(fā)庫,包括指定的組織或者部門發(fā)布的產(chǎn)品。獨(dú)立于核心開發(fā)庫
          • 激活的profiles列表,用于激活相應(yīng)profile
          • plugin 只有當(dāng)你的組織中有自己定的插件,用于命令行運(yùn)行在pom中定
          獨(dú)的用設(shè)置如下:
           
          <settings>
          <profiles>
          <profile>
          <id>property-overrides</id>
          <properties>
          <website.username>myuser</website.username>
          <website.pwd>test</website.username>
          </properties>
          </profile>
          </profiles>
          </settings>
           

          創(chuàng)建共享開發(fā)庫
             
          大多數(shù)組織將會(huì)創(chuàng)建自己的內(nèi)部開發(fā)庫,用于配置,而中心開發(fā)庫用于接maven
             
          設(shè)置內(nèi)部開發(fā)庫簡單的,使用http協(xié)議,可以使用存在的http 服務(wù)器。或者創(chuàng)建新的服務(wù),使用apache,或者jetty
              假
          設(shè)務(wù)器地址192.168.0.2 ,端口8080
              http://192.168.0.2:8080/repo-local
             
          設(shè)置另外一個(gè)開發(fā)庫,用于設(shè)項(xiàng)目的snapshothttp://192.168.0.2:8080/repo-snapshot
             
          中心,使用maven-proxy創(chuàng)建,當(dāng)然也可以創(chuàng)建自己的像。用于下本地中沒有的artifact


          maven-proxy
          設(shè)
             
          從網(wǎng)上直接下maven-proxy-standalone-0.2-app.jar和 proxy.properties
              在命令行中,直接運(yùn)行java -jar maven-proxy-standalone-0.2-app.jar  proxy.properties
          主要的配置:
          設(shè)置repo.list 中增加相應(yīng)就可以,如下定
          repo.list=repo1.maven.org,...
          #maven 的中心
          repo.repo1.maven.org.url=http://repo1.maven.org/maven2
          repo.repo1.maven.org.description=maven.org
          repo.repo1.maven.org.proxy=one
          repo.repo1.maven.org.hardfail=false
          repo.repo1.maven.org.cache.period=360000
          repo.repo1.maven.org.cache.failures=true
          以后所有的遠(yuǎn),都通此方式增加。便一下,不要忘了注原來的example,那是沒有訪問的。

          其他配置如
          端口號(hào) port=9999
          保存的位置 repo.local.store=target/repo
          serverName=http://localhost:9999

          創(chuàng)標(biāo)準(zhǔn)的組織pom
          共同的內(nèi)容,包括公司的結(jié)構(gòu),如組織,部以及團(tuán)隊(duì)
          察看一下maven 的自身,可以作很好的參考。
          scm
           
           

          <project>
          <modelVersion>4.0.0</modelVersion>
          <parent>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-parent</artifactId>
          <version>1</version>
          </parent>
          <groupId>org.apache.maven.scm</groupId>
          <artifactId>maven-scm</artifactId>
          <url>http://maven.apache.org/maven-scm/</url>
          ...
          <modules>
          <module>maven-scm-api</module>
          <module>maven-scm-providers</module>
          ...
          </modules>
          </project>    
           

          maven項(xiàng)目中可以看到如下定
           

           
          <project>
          <modelVersion>4.0.0</modelVersion>
          <parent>
          <groupId>org.apache</groupId>
          <artifactId>apache</artifactId>
          <version>1</version>
          </parent>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-parent</artifactId>
          <version>5</version>
          <url>http://maven.apache.org/</url>
          ...
          <mailingLists>
          <mailingList>
          <name>Maven Announcements List</name>
          <post>announce@maven.apache.org</post>
          ...
          </mailingList>
          </mailingLists>
          <developers>
          <developer>
          ...
          </developer>
          </developers>
          </project>    
           
          maven pom包括了共享的元素,如聲明件列表,開發(fā)者。并且大多數(shù)項(xiàng)apache組織
           
          <project>
          <modelVersion>4.0.0</modelVersion>
          <groupId>org.apache</groupId>
          <artifactId>apache</artifactId>
          <version>1</version>
          <organization>
          <name>Apache Software Foundation</name>
          <url>http://www.apache.org/</url>
          </organization>
          <url>http://www.apache.org/</url>
          ...
          <repositories>
          <repository>
          <id>apache.snapshots</id>
          <name>Apache Snapshot Repository</name>
          <url>http://svn.apache.org/maven-snapshot-repository</url>
          <releases>
          <enabled>false</enabled>
          </releases>
          </repository>
          </repositories>
          ...
          <distributionManagement>
          <repository>
          ...
          </repository>
          <snapshotRepository>
          ...
          </snapshotRepository>
          </distributionManagement>
          </project>    
           


          項(xiàng)目自身來,父pom很少更新。所以,最后的方式保存父pom文件在獨(dú)的版本控制區(qū)域,它check out,更改和配置.

          使用Continuum持久整合

              續(xù)整合自動(dòng)build你的項(xiàng)目,通一定的時(shí)間,包括所有的沖突在早期察,而不是發(fā)布的時(shí)候。另外持續(xù)整合也是一很好的開發(fā)方式,使團(tuán)隊(duì)產(chǎn)細(xì)微的,交互的變動(dòng),能更有效的支持平行開發(fā)進(jìn)程。
             
          可以使用mavencontinuum持久整合的服務(wù)
             
          安裝continuum,比較簡,使用以下的命令:
              C:\mvnbook\continuum-1.0.3> bin\win32\run
             
          可以通http://localhost:8082/continuum驗(yàn)證
             
          了支持continuum 發(fā)e-mail提醒,你需要相應(yīng)smtp務(wù)用于發(fā)送信息。默認(rèn)使用localhost:25,如果你沒有設(shè)置,編輯上面的文件改smtp-host設(shè)置。
             
          下一設(shè)svn
              svn co file://localhost/C:/mvnbook/svn/proficio/trunk proficio
             
          編輯pom.xml用于正確相應(yīng)e-mail地址。
           

           
          ...
          <ciManagement>
          <system>continuum</system>
          <url>http://localhost:8080/continuum
          <notifiers>
          <notifier>
          <type>mail</type>
          <configuration>
          <address>youremail@yourdomain.com</address>
          </configuration>
          </notifier>
          </notifiers>
          </ciManagement>
          ...
          <scm>
          <connection>
          scm:svn:file://localhost/c:/mvnbook/svn/proficio/trunk
          </connection>
          <developerConnection>
          scm:svn:file://localhost/c:/mvnbook/svn/proficio/trunk
          </developerConnection>
          </scm>
          ...
          <distributionManagement>
          <site>
          <id>website</id>
          <url>
          file://localhost/c:/mvnbook/repository/sites/proficio
          /reference/${project.version}
          </url>
          </site>
          </distributionManagement>    
           


          提交相應(yīng)的pom,然后執(zhí)行mvn install

          如果你返回http://localhost:8082/continuum,你會(huì)看到相
          應(yīng)項(xiàng)目列表。

          一旦你登
          后,你可以選擇mavan 2.0項(xiàng)目用于增加相應(yīng)項(xiàng)目。你可以增加你的url或者提交你的本地內(nèi)容。

          你可以使用本地pom url,如下file://localhost/c:mvnbook/proficio/pom.xml

          在提交了此url后,continuum將會(huì)返回相應(yīng)的成功信息。
          以下的原用于更好的幫助持續(xù)整合:
          早提交,
          經(jīng)常提交:當(dāng)用戶經(jīng)常提交時(shí),持續(xù)整合是最有效的。并不意味著,提交不正確的代
          經(jīng)常運(yùn)行build:用于最快檢測
          盡快修正失:當(dāng)失敗發(fā)時(shí)應(yīng)該馬上修正失
          一個(gè)有效的版本
          運(yùn)行clean build
          運(yùn)行
          復(fù)雜測試
          build
          所有的項(xiàng)結(jié)構(gòu)分支
          續(xù)運(yùn)行項(xiàng)目的拷
           
          posted on 2008-01-10 19:41 禮物 閱讀(1245) 評論(1)  編輯  收藏 所屬分類: maven2

          評論

          # re: maven2完全使用手冊[未登錄] 2008-10-15 11:17 test
          比ant難多了啊  回復(fù)  更多評論
            

          主站蜘蛛池模板: 瓦房店市| 台东市| 蒙自县| 正镶白旗| 门头沟区| 平果县| 延吉市| 河西区| 遂川县| 新兴县| 五寨县| 奉贤区| 吉安市| 宿州市| 垦利县| 湖州市| 虹口区| 密云县| 买车| 鄂温| 宁陵县| 益阳市| 福鼎市| 图木舒克市| 平谷区| 达州市| 孙吴县| 大新县| 西丰县| 汨罗市| 合肥市| 兴文县| 离岛区| 金坛市| 沁阳市| 桂平市| 什邡市| 道孚县| 个旧市| 六盘水市| 紫阳县|