随着,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吧!