空間站

          北極心空

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            15 Posts :: 393 Stories :: 160 Comments :: 0 Trackbacks
          對于團隊來說,建立統一的開發環境是必須的,而maven能很好幫助建立統一的環境。下面就介紹如何更有效的進行統一的配置。
          準備工作:
             下載必須的軟件:
          maven2: http://maven.apache.org/download.html 最主要的
          maven-proxy:用來代理repository,使用代理來訪問多個遠程庫
                      http://maven-proxy.codehaus.org/
          continuum:一個不錯的持續整合工具,用于自動build。支持ant,maven
          http://maven.apache.org/continuum/
          svn:版本控制工具

          創建一致的開發環境
             在共享的開發環境中,更好的建議是保持maven的兩個不同的配置文件分別管理,包括共享和用戶自定義設置。共同的配置包括在安裝目錄中,而單獨的開發設置保存在用戶本地目錄。
              全局的配置文件settings.xml
          xml 代碼
          1.    <servers>  
          2.        //公司內部庫,所有的release版本,serverid對應于repository id,用于在deploy時,訪問使用,主要保存用戶名和密碼  
          3. <server>  
          4. <id>internal</id>  
          5. <username>${website.username}</username>  
          6. <password>${website.pwd}</password>  
          7. <filePermissions>664</filePermissions>  
          8. <directoryPermissions>775</directoryPermissions>  
          9. </server>  
          10. //目前的開發庫,用于snapshot庫  
          11. <server>  
          12. <id>snapshot</id>  
          13. <username>${website.username}</username>  
          14. <password>${website.pwd}</password>  
          15. <filePermissions>664</filePermissions>  
          16. <directoryPermissions>775</directoryPermissions>  
          17. </server>  
          18. </servers>  
          19.   
          20. <profiles>  
          21. <!--定義核心庫 maven 鏡像,由maven-proxy實現-->  
          22. <profile>  
          23. <id>central-repo</id>  
          24. <repositories>  
          25. <repository>  
          26. <id>central</id>  
          27. <name>Internal Repository</name>  
          28. <url>http://192.168.0.2:9999/repository</url>  
          29. </repository>  
          30. </repositories>  
          31. <pluginRepositories>  
          32. <pluginRepository>  
          33. <id>central</id>  
          34. <name>Internal Repository</name>  
          35. <url>http://192.168.0.2:9999/repository</url>  
          36. </pluginRepository>  
          37. </pluginRepositories>  
          38. </profile>  
          39.   
          40. <!--定義內部庫,包括公司的所有release版本-->  
          41. <profile>  
          42. <id>internal-repo</id>  
          43. <repositories>  
          44. <repository>  
          45. <id>internal</id>  
          46. <name>Internal Repository</name>  
          47. <url>http://192.168.0.2:8080/repo-local</url>  
          48. <releases>  
          49. <enabled>true</enabled>  
          50. <updatePolicy>never</updatePolicy>  
          51. <checksumPolicy>warn</checksumPolicy>  
          52. </releases>  
          53. </repository>  
          54. </repositories>  
          55. <pluginRepositories>  
          56. <pluginRepository>  
          57. <id>internal</id>  
          58. <name>Internal Plugin Repository</name>  
          59. <url>http://192.168.0.2:8080/repo-local</url>  
          60. <releases>  
          61. <enabled>true</enabled>  
          62. <updatePolicy>never</updatePolicy>  
          63. <checksumPolicy>warn</checksumPolicy>  
          64. </releases>  
          65. </pluginRepository>  
          66. </pluginRepositories>  
          67. </profile>  
          68. <!--定義內部開發庫 ,也可以合并snapshot和release-->  
          69. <profile>  
          70. <id>snapshot-repo</id>  
          71. <repositories>  
          72. <repository>  
          73. <id>snapshot</id>  
          74. <name>Internal Repository</name>  
          75. <url>http://192.168.0.2:8080/repo-snapshot</url>  
          76. <snapshots>  
          77. <enabled>true</enabled>  
          78. <updatePolicy>interval:60</updatePolicy>  
          79. <checksumPolicy>warn</checksumPolicy>  
          80. </snapshots>  
          81. </repository>  
          82. </repositories>  
          83. <pluginRepositories>  
          84. <pluginRepository>  
          85. <id>snapshot</id>  
          86. <name>Internal Plugin Repository</name>  
          87. <url>http://192.168.0.2:8080/repo-snapshot</url>  
          88. <snapshots>  
          89. <enabled>true</enabled>  
          90. <updatePolicy>interval:60</updatePolicy>  
          91. <checksumPolicy>warn</checksumPolicy>  
          92. </snapshots>  
          93. </pluginRepository>  
          94. </pluginRepositories>  
          95. </profile>  
          96. </profiles>  
          97. <!-- 激活相應得配置-->  
          98. <activeProfiles>  
          99. <activeProfile>central-repo</activeProfile>  
          100. <activeProfile>internal-repo</activeProfile>  
          101. <activeProfile>snapshot-repo</activeProfile>  
          102. </activeProfiles>  
          103. <!-- 插件默認groupId -->  
          104. <pluginGroups>  
          105. <pluginGroup>com.mycompany.plugins</pluginGroup>  
          106. </pluginGroups>  

          包括了以下的共享因素:
          服務器設置典型是共同的,只有用戶名需要在用戶環境中設置。使用一致的定義來配置共同的設置
          profile定義了共同的因素,內部開發庫,包括指定的組織或者部門發布的產品。這些庫獨立于核心開發庫。
          激活的profiles列表,用于激活相應的profile
          plugin 組只有當你的組織中有自己定義的插件,用于命令行運行在pom中定義。

          對于單獨的用戶來說,設置如下:
          xml 代碼
          1. <settings>  
          2. <profiles>  
          3. <profile>  
          4. <id>property-overrides</id>  
          5. <properties>  
          6. <website.username>myuser</website.username>  
          7. <website.pwd>test</website.username>  
          8. </properties>  
          9. </profile>  
          10. </profiles>  
          11. </settings>  

          創建共享開發庫
              大多數組織將會創建自己的內部開發庫,用于配置,而中心開發庫用于連接maven
              設置內部開發庫是簡單的,使用http協議,可以使用存在的http 服務器。或者創建新的服務,使用apache,或者jetty
              假設服務器地址192.168.0.2 ,端口8080
              http://192.168.0.2:8080/repo-local
              設置另外一個開發庫,用于設置項目的snapshot庫http://192.168.0.2:8080/repo-snapshot
              中心鏡像庫,使用maven-proxy創建,當然也可以創建自己的鏡像。用于下載本地庫中沒有的artifact
          maven-proxy 設置
              從網上直接下載maven-proxy-standalone-0.2-app.jar和 proxy.properties
              在命令行中,直接運行java -jar maven-proxy-standalone-0.2-app.jar  proxy.properties
          主要的配置:
          設置repo.list 中增加相應的庫就可以,如下定義:
          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
          以后所有的遠程庫,都通過此方式增加。順便說一下,不要忘了注釋原來的example,那是沒有辦法訪問的。

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

          創建標準的組織pom
          定義共同的內容,包括公司的結構,如組織,部門以及團隊。
          察看一下maven 的自身,可以作為很好的參考。
          如scm
           
          xml 代碼
          1. <project>  
          2. <modelVersion>4.0.0</modelVersion>  
          3. <parent>  
          4. <groupId>org.apache.maven</groupId>  
          5. <artifactId>maven-parent</artifactId>  
          6. <version>1</version>  
          7. </parent>  
          8. <groupId>org.apache.maven.scm</groupId>  
          9. <artifactId>maven-scm</artifactId>  
          10. <url>http://maven.apache.org/maven-scm/</url>  
          11. ...  
          12. <modules>  
          13. <module>maven-scm-api</module>  
          14. <module>maven-scm-providers</module>  
          15. ...  
          16. </modules>  
          17. </project>      
           

          在maven父項目中可以看到如下定義:
           
          xml 代碼
          1. <project>  
          2. <modelVersion>4.0.0</modelVersion>  
          3. <parent>  
          4. <groupId>org.apache</groupId>  
          5. <artifactId>apache</artifactId>  
          6. <version>1</version>  
          7. </parent>  
          8. <groupId>org.apache.maven</groupId>  
          9. <artifactId>maven-parent</artifactId>  
          10. <version>5</version>  
          11. <url>http://maven.apache.org/</url>  
          12. ...  
          13. <mailingLists>  
          14. <mailingList>  
          15. <name>Maven Announcements List</name>  
          16. <post>announce@maven.apache.org</post>  
          17. ...  
          18. </mailingList>  
          19. </mailingLists>  
          20. <developers>  
          21. <developer>  
          22. ...  
          23. </developer>  
          24. </developers>  
          25. </project>       

          maven 父pom包括了共享的元素,如聲明郵件列表,開發者。并且大多數項目繼承apache組織:
           
          xml 代碼
          1. <project>  
          2. <modelVersion>4.0.0</modelVersion>  
          3. <groupId>org.apache</groupId>  
          4. <artifactId>apache</artifactId>  
          5. <version>1</version>  
          6. <organization>  
          7. <name>Apache Software Foundation</name>  
          8. <url>http://www.apache.org/</url>  
          9. </organization>  
          10. <url>http://www.apache.org/</url>  
          11. ...  
          12. <repositories>  
          13. <repository>  
          14. <id>apache.snapshots</id>  
          15. <name>Apache Snapshot Repository</name>  
          16. <url>http://svn.apache.org/maven-snapshot-repository</url>  
          17. <releases>  
          18. <enabled>false</enabled>  
          19. </releases>  
          20. </repository>  
          21. </repositories>  
          22. ...  
          23. <distributionManagement>  
          24. <repository>  
          25. ...  
          26. </repository>  
          27. <snapshotRepository>  
          28. ...  
          29. </snapshotRepository>  
          30. </distributionManagement>  
          31. </project>       

          對于項目自身來說,父pom很少更新。所以,最后的方式保存父pom文件在單獨的版本控制區域,它們能夠check out,更改和配置
          使用Continuum持久整合
              持續整合自動build你的項目,通過一定的時間,包括所有的沖突在早期察覺,而不是發布的時候。另外持續整合也是一種很好的開發方式,使團隊成員能產生細微的,交互的變動,能更有效的支持平行開發進程。
              可以使用maven的continuum作為持久整合的服務。
              安裝continuum,比較簡,使用以下的命令:
              C:\mvnbook\continuum-1.0.3> bin\win32\run
              可以通過http://localhost:8082/continuum來驗證
              為了支持continuum 發送e-mail提醒,你需要相應的smtp服務用于發送信息。默認使用localhost:25,如果你沒有設置,編輯上面的文件改變smtp-host設置。
              下一步,設置svn目錄:
              svn co file://localhost/C:/mvnbook/svn/proficio/trunk proficio
              編輯pom.xml用于正確相應得e-mail地址。
           
          xml 代碼
          1. ...  
          2. <ciManagement>  
          3. <system>continuum</system>  
          4. <url>http://localhost:8080/continuum  
          5. <notifiers>  
          6. <notifier>  
          7. <type>mail</type>  
          8. <configuration>  
          9. <address>youremail@yourdomain.com</address>  
          10. </configuration>  
          11. </notifier>  
          12. </notifiers>  
          13. </ciManagement>  
          14. ...  
          15. <scm>  
          16. <connection>  
          17. scm:svn:file://localhost/c:/mvnbook/svn/proficio/trunk  
          18. </connection>  
          19. <developerConnection>  
          20. scm:svn:file://localhost/c:/mvnbook/svn/proficio/trunk  
          21. </developerConnection>  
          22. </scm>  
          23. ...  
          24. <distributionManagement>  
          25. <site>  
          26. <id>website</id>  
          27. <url>  
          28. file://localhost/c:/mvnbook/repository/sites/proficio  
          29. /reference/${project.version}  
          30. </url>  
          31. </site>  
          32. </distributionManagement>      
           

          提交相應的pom,然后執行mvn install
          如果你返回http://localhost:8082/continuum,你會看到相應的項目列表。
          一旦你登錄后,你可以選擇mavan 2.0項目用于增加相應的項目。你可以增加你的url或者提交你的本地內容。
          你可以使用本地pom url,如下file://localhost/c:mvnbook/proficio/pom.xml
          在提交了此url后,continuum將會返回相應的成功信息。
          以下的原則用于更好的幫助持續整合:
          早提交,經常提交:當用戶經常提交時,持續整合是最有效的。這并不意味著,提交不正確的代碼。
          經常運行build:用于最快檢測失敗
          盡快修正失敗:當失敗發生時,應該馬上修正失敗
          建議一個有效的版本
          運行clean build
          運行復雜的綜合測試
          build所有的項目結構分支
          持續運行項目的拷貝
          posted on 2007-08-09 13:16 蘆葦 閱讀(454) 評論(0)  編輯  收藏 所屬分類: JAVA
          主站蜘蛛池模板: 黄平县| 环江| 永嘉县| 大悟县| 黄陵县| 蓝山县| 民乐县| 高雄县| 洪泽县| 旺苍县| 乌兰浩特市| 金山区| 宜良县| 宜丰县| 乐业县| 克拉玛依市| 莒南县| 玉龙| 滁州市| 雷波县| 荣昌县| 义马市| 报价| 合川市| 惠州市| 绵阳市| 罗江县| 岫岩| 靖边县| 武平县| 泽库县| 西畴县| 肥乡县| 甘洛县| 沙田区| 东城区| 利津县| 光山县| 遂溪县| 湘潭市| 平果县|