隨着,Maven管理項目越來越來流行,Maven最大的好處是依賴包的倉庫集中管理,Maven可以使用繼承和聚合。
1.Maven多模塊項目。
Maven多模塊項目需要一個父工程來聚合其他模塊,就要就是pom.xml文件:
<modules> <module>模塊1</module> <module>模塊2</module> </modules>
然后在子模塊中,聲明父工程,子模塊中代碼如下:
<parent> <groupId>父工程的groupId</groupId> <artifactId>父工程的artifactId</artifactId> <version>版本號</version> <relativePath>../..</relativePath> </parent>
2.Maven合並多web項目。
Maven的多模塊的maven-war-plugin插件overlays屬性來處理,項目的pom.xml:
<build> <finalName>項目發布名稱</finalName> <pulgins> <pulgin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <packagingExcludes> <overlays> <overlay> <groupId>web1</groupId> <artifactId></artifactId> </overlay> <overlay> <groupId>web2</groupId> <artifactId></artifactId> </overlay> <overlay> <groupId>web3</groupId> <artifactId></artifactId> </overlay> </overlays> </packginExcludes> </configuration> </pulgin> </pulgins> <resources> <resource> <directory>路勁</directory> <excludes> <exclude>config/**</exclude> </excludes> </resource> <resource> <directory>src/main/resources</directory> </resource> </resources> </build>
細心的用戶會發現,其實這完全和我們原來的構建,部署方式完全一樣,是的,maven沒有那么復雜,m2eclipse maven plugin已經幫我們做好了太多的事情,maven只會讓我們項目之間的遷移更方便,更簡潔,這也是我喜歡上maven的重要原因。
我是一個絕對的maven新手,上面的文章用的也只是maven的皮毛而已,maven更多的構建功能還需要深入去研究,上面文章只是想告訴那些想嘗試maven的新手,其實maven不但對代碼管理帶來了很大的方便,而且完全可以不改變我們原有的開發習慣。所以,盡情的擁抱maven吧!