网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

maven的聚合模块和pom继承使用

1.什么是maven的聚合模块?

聚合模块为项目目录的最顶层,其他模块作为聚合模块子目录而存在。目的是为一次构建多个项目模块。

成都创新互联公司专注于临淄网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供临淄营销型网站建设,临淄网站制作、临淄网页设计、临淄网站官网定制、微信小程序开发服务,打造临淄网络公司原创品牌,更为您提供临淄网站排名全网营销落地服务。

 

1.1 项目结构

我自己化了一个关于项目的关系:

maven的聚合模块和pom继承使用

 

1.2 pom标签配置-module下载 

    maven-aggregate作为maven pom项目,需要定义pom.xml的 packaging 为 pom类型

    我们还是参照 maven的依赖特性,冲突解决(五) 创建 maven-01 maven-02  maven-03工程,通过maven-aggregate pom工程 对这三个maven项目做一个聚合,配置如下:

  maven的聚合模块和pom继承使用

Xml代码  下载 

  1.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  

  2.   4.0.0  

  3.   

  4.   com.sohu.train  

  5.   maven-aggregate  

  6.   0.0.1-SNAPSHOT  

  7.   pom  

  8.   

  9.     

  10.     

  11.     ../maven-01  

  12.     ../maven-02  

  13.     ..maven-03  

  14.      

  15.     

  16.   

  

   对 maven-aggregate执行下mvn clean compile

  

Xml代码  下载 

  1. [INFO] Scanning for projects...  

  2. [WARNING]   

  3. [WARNING] Some problems were encountered while building the effective model for com.sohu.train:maven-02:jar:1.0-SNAPSHORT  

  4. [WARNING] 'dependencies.dependency.exclusions.exclusion.groupId' for junit:junit:jar is missing. @ line 38, column 16  

  5. [WARNING] 'dependencies.dependency.exclusions.exclusion.artifactId' for junit:junit:jar is missing. @ line 38, column 16  

  6. [WARNING]   

  7. [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.  

  8. [WARNING]   

  9. [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.  

  10. [WARNING]   

  11. [INFO] ------------------------------------------------------------------------  

  12. [INFO] Reactor Build Order:   //构建 maven 的反应堆,执行清理 编译的顺序  

  13. [INFO]   

  14. [INFO] maven-02  

  15. [INFO] maven-01  

  16. [INFO] maven-03  

  17. [INFO] maven-aggregate  

  18. [INFO]                                                                           

  19. [INFO] ------------------------------------------------------------------------  

  20. [INFO] Building maven-02 1.0-SNAPSHORT  

  21. [INFO] ------------------------------------------------------------------------  

  22. [INFO]   

  23. [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-02 ---  

  24. [INFO] Deleting E:\train\test\maven-02\target  

  25. [INFO]   

  26. [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-02 ---  

  27. [INFO] Using 'UTF-8' encoding to copy filtered resources.  

  28. [INFO] skip non existing resourceDirectory E:\train\test\maven-02\src\main\resources  

  29. [INFO]   

  30. [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-02 ---  

  31. [INFO] Changes detected - recompiling the module!  

  32. [INFO] Compiling 1 source file to E:\train\test\maven-02\target\classes  

  33. [INFO]                                                                           

  34. [INFO] ------------------------------------------------------------------------  

  35. [INFO] Building maven-01 1.0-SNAPSHOT  

  36. [INFO] ------------------------------------------------------------------------  

  37. [INFO]   

  38. [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-01 ---  

  39. [INFO] Deleting E:\train\test\maven-01\target  

  40. [INFO]   

  41. [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-01 ---  

  42. [INFO] Using 'UTF-8' encoding to copy filtered resources.  

  43. [INFO] Copying 1 resource  

  44. [INFO]   

  45. [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-01 ---  

  46. [INFO] Changes detected - recompiling the module!  

  47. [INFO] Compiling 1 source file to E:\train\test\maven-01\target\classes  

  48. [INFO]                                                                           

  49. [INFO] ------------------------------------------------------------------------  

  50. [INFO] Building maven-03 0.0.1-SNAPSHOT  

  51. [INFO] ------------------------------------------------------------------------  

  52. [INFO]   

  53. [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-03 ---  

  54. [INFO] Deleting E:\train\test\maven-03\target  

  55. [INFO]   

  56. [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-03 ---  

  57. [INFO] Using 'UTF-8' encoding to copy filtered resources.  

  58. [INFO] skip non existing resourceDirectory E:\train\test\maven-03\src\main\resources  

  59. [INFO]   

  60. [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-03 ---  

  61. [INFO] Changes detected - recompiling the module!  

  62. [INFO] Compiling 1 source file to E:\train\test\maven-03\target\classes  

  63. [INFO]                                                                           

  64. [INFO] ------------------------------------------------------------------------  

  65. [INFO] Building maven-aggregate 0.0.1-SNAPSHOT  

  66. [INFO] ------------------------------------------------------------------------  

  67. [INFO]   

  68. [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ maven-aggregate ---  

  69. [INFO] ------------------------------------------------------------------------  

  70. [INFO] Reactor Summary:     // 可以看到 对3个maven项目 一起执行编译  

  71. [INFO]   

  72. [INFO] maven-02 ........................................... SUCCESS [  1.874 s]  

  73. [INFO] maven-01 ........................................... SUCCESS [  0.108 s]  

  74. [INFO] maven-03 ........................................... SUCCESS [  0.158 s]  

  75. [INFO] maven-aggregate .................................... SUCCESS [  0.002 s]  

  76. [INFO] ------------------------------------------------------------------------  

  77. [INFO] BUILD SUCCESS  

  78. [INFO] ------------------------------------------------------------------------  

  79. [INFO] Total time: 2.263 s  

  80. [INFO] Finished at: 2016-01-15T14:35:41+08:00  

  81. [INFO] Final Memory: 14M/227M  

  82. [INFO] ------------------------------------------------------------------------  

 这样我们就完成 maven对子模块的聚合 ,像我们平常用的dubbo jetty tomcat spring hibernate等等 都是按模块 去开发,一次编译 各个模块都能紧密联系在一起了。我们在平常开发项目也需要适当的去分模块开发,

这是dubbo的子模块,分了很多子模块:下载 

 maven的聚合模块和pom继承使用

 

2.什么是pom继承?

pom继承是为了抽出重复配置,通常配置在父模块中,为子模块提供使用,这样可以做到“一处声明,处处使用”。

2.1 继承结构

下载 

2.2 pom标签配置-parent,*Management

 1.常用的pom被继承的元素

 

Xml代码  下载 

  1. groupId :项目组 ID ,项目坐标的核心元素;    

  2. version :项目版本,项目坐标的核心元素;    

  3. description :项目的描述信息;    

  4. properties :自定义的 Maven 属性;    

  5. dependencies :项目的依赖配置;    

  6. dependencyManagement :醒目的依赖管理配置;    

  7. repositories :项目的仓库配置;    

  8. build :包括项目的源码目录配置、输出目录配置、插件配置、插件管理配置等;    

 

 1.配置maven-aggregate pom文件:

Xml代码  下载 

  1.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  

  2.   4.0.0  

  3.   

  4.   com.sohu.train  

  5.   maven-aggregate  

  6.   0.0.1-SNAPSHOT  

  7.   pom  

  8.   

  9.     

  10.     

  11.     ../maven-01  

  12.     ../maven-02  

  13.     ../maven-03  

  14.      

  15.     

  16.     

  17.     3.8.1  

  18.     

  19.     

  20.     

  21.     

  22.       

  23.           

  24.             junit  

  25.             junit  

  26.             ${junit.version}  

  27.             test  

  28.           

  29.          

  30.     

  31.   

 maven-01,maven-02,maven-03 需要配置parent ,dependencies,同时对junit做一个依赖,3个工程的pom配置如下:

Xml代码  下载 

  1.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  

  2.     4.0.0  

  3.       

  4.       

  5.         com.sohu.train  

  6.         maven-aggregate  

  7.         0.0.1-SNAPSHOT  

  8.         ../maven-aggregate/pom.xml  

  9.       

  10.     maven-03  

  11.     jar  

  12.           

  13.       

  14.           

  15.             junit  

  16.             junit  

  17.           

  18.       

  19.   

  这样就完成pom的继承,讲公用的jar一次配置,就可以实现多处引用了。

 


新闻标题:maven的聚合模块和pom继承使用
文章出自:http://bjjierui.cn/article/pdsgdj.html

其他资讯