一、建立一个maven工程 pom类型

统一管理依赖以及版本号

子工程不会使用所有的定义的依赖

子工程使用依赖时无需指定版本号

pom.xml

  1. <project 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/maven-4.0.0.xsd">
  2. <modelVersion>4.0.0</modelVersion>
  3. <groupId>com.spiritmark.cyf</groupId>
  4. <artifactId>environment</artifactId>
  5. <version>0.0.1-SNAPSHOT</version>
  6. <packaging>pom</packaging>
  7. <!-- 集中定义依赖版本号 -->
  8. <properties>
  9. <junit.version>4.10</junit.version>
  10. <spring.version>4.2.2.RELEASE</spring.version>
  11. <mybatis.version>3.2.8</mybatis.version>
  12. <mybatis.spring.version>1.2.2</mybatis.spring.version>
  13. <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
  14. <mysql.version>5.1.47</mysql.version>
  15. <slf4j.version>1.6.4</slf4j.version>
  16. <jackson.version>2.4.2</jackson.version>
  17. <druid.version>1.0.9</druid.version>
  18. <httpclient.version>4.3.5</httpclient.version>
  19. <jstl.version>1.2</jstl.version>
  20. <servlet-api.version>2.5</servlet-api.version>
  21. <jsp-api.version>2.0</jsp-api.version>
  22. <joda-time.version>2.5</joda-time.version>
  23. <commons-lang3.version>3.3.2</commons-lang3.version>
  24. <commons-io.version>1.3.2</commons-io.version>
  25. </properties>
  26. <!-- 管理jar包,不会引入 ,如果子工程需要哪些jar包,则具体地在子工程中引入,不过不需要写版本号-->
  27. <dependencyManagement>
  28. <dependencies>
  29. <!-- 单元测试 -->
  30. <dependency>
  31. <groupId>junit</groupId>
  32. <artifactId>junit</artifactId>
  33. <version>${junit.version}</version>
  34. <scope>test</scope>
  35. </dependency>
  36. <!-- Spring -->
  37. <dependency>
  38. <groupId>org.springframework</groupId>
  39. <artifactId>spring-context</artifactId>
  40. <version>${spring.version}</version>
  41. </dependency>
  42. <dependency>
  43. <groupId>org.springframework</groupId>
  44. <artifactId>spring-beans</artifactId>
  45. <version>${spring.version}</version>
  46. </dependency>
  47. <dependency>
  48. <groupId>org.springframework</groupId>
  49. <artifactId>spring-webmvc</artifactId>
  50. <version>${spring.version}</version>
  51. </dependency>
  52. <dependency>
  53. <groupId>org.springframework</groupId>
  54. <artifactId>spring-jdbc</artifactId>
  55. <version>${spring.version}</version>
  56. </dependency>
  57. <dependency>
  58. <groupId>org.springframework</groupId>
  59. <artifactId>spring-aspects</artifactId>
  60. <version>${spring.version}</version>
  61. </dependency>
  62. <!-- Mybatis -->
  63. <dependency>
  64. <groupId>org.mybatis</groupId>
  65. <artifactId>mybatis</artifactId>
  66. <version>${mybatis.version}</version>
  67. </dependency>
  68. <dependency>
  69. <groupId>org.mybatis</groupId>
  70. <artifactId>mybatis-spring</artifactId>
  71. <version>${mybatis.spring.version}</version>
  72. </dependency>
  73. <!-- MySql -->
  74. <dependency>
  75. <groupId>mysql</groupId>
  76. <artifactId>mysql-connector-java</artifactId>
  77. <version>${mysql.version}</version>
  78. </dependency>
  79. <dependency>
  80. <groupId>org.slf4j</groupId>
  81. <artifactId>slf4j-log4j12</artifactId>
  82. <version>${slf4j.version}</version>
  83. </dependency>
  84. <!-- Jackson Json处理工具包 -->
  85. <dependency>
  86. <groupId>com.fasterxml.jackson.core</groupId>
  87. <artifactId>jackson-databind</artifactId>
  88. <version>${jackson.version}</version>
  89. </dependency>
  90. <!-- 连接池 -->
  91. <dependency>
  92. <groupId>com.jolbox</groupId>
  93. <artifactId>bonecp-spring</artifactId>
  94. <version>0.8.0.RELEASE</version>
  95. </dependency>
  96. <!-- httpclient -->
  97. <dependency>
  98. <groupId>org.apache.httpcomponents</groupId>
  99. <artifactId>httpclient</artifactId>
  100. <version>${httpclient.version}</version>
  101. </dependency>
  102. <!-- JSP相关 -->
  103. <dependency>
  104. <groupId>jstl</groupId>
  105. <artifactId>jstl</artifactId>
  106. <version>${jstl.version}</version>
  107. </dependency>
  108. <dependency>
  109. <groupId>javax.servlet</groupId>
  110. <artifactId>servlet-api</artifactId>
  111. <version>${servlet-api.version}</version>
  112. <scope>provided</scope>
  113. </dependency>
  114. <dependency>
  115. <groupId>javax.servlet</groupId>
  116. <artifactId>jsp-api</artifactId>
  117. <version>${jsp-api.version}</version>
  118. <scope>provided</scope>
  119. </dependency>
  120. <!-- 时间操作组件 -->
  121. <dependency>
  122. <groupId>joda-time</groupId>
  123. <artifactId>joda-time</artifactId>
  124. <version>${joda-time.version}</version>
  125. </dependency>
  126. <!-- Apache工具组件 -->
  127. <dependency>
  128. <groupId>org.apache.commons</groupId>
  129. <artifactId>commons-lang3</artifactId>
  130. <version>${commons-lang3.version}</version>
  131. </dependency>
  132. <dependency>
  133. <groupId>org.apache.commons</groupId>
  134. <artifactId>commons-io</artifactId>
  135. <version>${commons-io.version}</version>
  136. </dependency>
  137. </dependencies>
  138. </dependencyManagement>
  139. <build>
  140. <finalName>${project.artifactId}</finalName>
  141. <plugins>
  142. <!-- 资源文件拷贝插件 -->
  143. <plugin>
  144. <groupId>org.apache.maven.plugins</groupId>
  145. <artifactId>maven-resources-plugin</artifactId>
  146. <version>2.7</version>
  147. <configuration>
  148. <encoding>UTF-8</encoding>
  149. </configuration>
  150. </plugin>
  151. <!-- java编译插件 -->
  152. <plugin>
  153. <groupId>org.apache.maven.plugins</groupId>
  154. <artifactId>maven-compiler-plugin</artifactId>
  155. <version>3.2</version>
  156. <configuration>
  157. <source>1.8</source>
  158. <target>1.8</target>
  159. <encoding>UTF-8</encoding>
  160. </configuration>
  161. </plugin>
  162. </plugins>
  163. <pluginManagement>
  164. <plugins>
  165. <!-- 配置Tomcat插件 -->
  166. <plugin>
  167. <groupId>org.apache.tomcat.maven</groupId>
  168. <artifactId>tomcat7-maven-plugin</artifactId>
  169. <version>2.2</version>
  170. </plugin>
  171. </plugins>
  172. </pluginManagement>
  173. </build>
  174. </project>

二、新创建一个maven工程

在pom.xml中,继承父工程,依赖去掉版本号

  1. <project 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/maven-4.0.0.xsd">
  2. <modelVersion>4.0.0</modelVersion>
  3. <!-- 使用继承 -->
  4. <parent>
  5. <groupId>com.spiritmark.cyf</groupId>
  6. <artifactId>environment</artifactId>
  7. <version>0.0.1-SNAPSHOT</version>
  8. </parent>
  9. <groupId>com.spiritmark.cyf</groupId>
  10. <artifactId>usermanage</artifactId>
  11. <version>0.0.1-SNAPSHOT</version>
  12. <packaging>war</packaging>
  13. <dependencies>
  14. <dependency>
  15. <groupId>org.apache.poi</groupId>
  16. <artifactId>poi</artifactId>
  17. <version>3.10.1</version>
  18. </dependency>
  19. <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
  20. <dependency>
  21. <groupId>com.fasterxml.jackson.core</groupId>
  22. <artifactId>jackson-databind</artifactId>
  23. </dependency>
  24. <!-- 时间操作组件 -->
  25. <dependency>
  26. <groupId>joda-time</groupId>
  27. <artifactId>joda-time</artifactId>
  28. </dependency>
  29. <!-- spring-webmvc -->
  30. <dependency>
  31. <groupId>org.springframework</groupId>
  32. <artifactId>spring-webmvc</artifactId>
  33. </dependency>
  34. <!-- 切面 -->
  35. <dependency>
  36. <groupId>org.springframework</groupId>
  37. <artifactId>spring-aspects</artifactId>
  38. </dependency>
  39. <!-- spring的jdbc -->
  40. <dependency>
  41. <groupId>org.springframework</groupId>
  42. <artifactId>spring-jdbc</artifactId>
  43. </dependency>
  44. <dependency>
  45. <groupId>org.springframework</groupId>
  46. <artifactId>spring-test</artifactId>
  47. <version>4.3.7.RELEASE</version>
  48. </dependency>
  49. <!-- mysql的驱动 -->
  50. <dependency>
  51. <groupId>mysql</groupId>
  52. <artifactId>mysql-connector-java</artifactId>
  53. </dependency>
  54. <!-- mybatis -->
  55. <dependency>
  56. <groupId>org.mybatis</groupId>
  57. <artifactId>mybatis</artifactId>
  58. </dependency>
  59. <!-- mybatis于spring整合的jar -->
  60. <dependency>
  61. <groupId>org.mybatis</groupId>
  62. <artifactId>mybatis-spring</artifactId>
  63. </dependency>
  64. <!-- generator -->
  65. <dependency>
  66. <groupId>org.mybatis.generator</groupId>
  67. <artifactId>mybatis-generator-core</artifactId>
  68. <version>1.3.5</version>
  69. </dependency>
  70. <!-- jstl -->
  71. <dependency>
  72. <groupId>javax.servlet</groupId>
  73. <artifactId>jstl</artifactId>
  74. <version>1.2</version>
  75. </dependency>
  76. <!-- pagehelper -->
  77. <dependency>
  78. <groupId>com.github.pagehelper</groupId>
  79. <artifactId>pagehelper</artifactId>
  80. <version>5.1.2</version>
  81. </dependency>
  82. <!-- c3p0数据源 -->
  83. <dependency>
  84. <groupId>com.mchange</groupId>
  85. <artifactId>c3p0</artifactId>
  86. <version>0.9.5.2</version>
  87. </dependency>
  88. <!-- -->
  89. <dependency>
  90. <groupId>javax.servlet</groupId>
  91. <artifactId>javax.servlet-api</artifactId>
  92. <version>3.1.0</version>
  93. <scope>provided</scope>
  94. </dependency>
  95. <!-- -->
  96. <dependency>
  97. <groupId>org.slf4j</groupId>
  98. <artifactId>slf4j-log4j12</artifactId>
  99. </dependency>
  100. <!-- https://mvnrepository.com/artifact/junit/junit -->
  101. <dependency>
  102. <groupId>junit</groupId>
  103. <artifactId>junit</artifactId>
  104. <scope>test</scope>
  105. </dependency>
  106. <!-- 文件上传 -->
  107. <dependency>
  108. <groupId>commons-fileupload</groupId>
  109. <artifactId>commons-fileupload</artifactId>
  110. <version>1.3.1</version>
  111. </dependency>
  112. <dependency>
  113. <groupId>org.apache.shiro</groupId>
  114. <artifactId>shiro-core</artifactId>
  115. <version>1.4.0</version>
  116. </dependency>
  117. <dependency>
  118. <groupId>org.apache.shiro</groupId>
  119. <artifactId>shiro-web</artifactId>
  120. <version>1.4.0</version>
  121. </dependency>
  122. <dependency>
  123. <groupId>org.apache.shiro</groupId>
  124. <artifactId>shiro-ehcache</artifactId>
  125. <version>1.4.0</version>
  126. </dependency>
  127. <dependency>
  128. <groupId>org.apache.shiro</groupId>
  129. <artifactId>shiro-spring</artifactId>
  130. <version>1.4.0</version>
  131. </dependency>
  132. </dependencies>
  133. </project>

插件配置

  1. <build>
  2. <plugins>
  3. <!-- 配置tomcat插件 -->
  4. <plugin>
  5. <groupId>org.apache.tomcat.maven</groupId>
  6. <artifactId>tomcat7-maven-plugin</artifactId>
  7. <!-- tomcat配置 -->
  8. <configuration>
  9. <!-- 端口号 -->
  10. <port>8001</port>
  11. <!-- 项目的路径 -->
  12. <path>/</path>
  13. </configuration>
  14. </plugin>
  15. </plugins>
  16. </build>

maven继承父工程统一版本号的更多相关文章

  1. maven问题:如何不继承父工程的依赖

    在maven中,使用父工程来管理所有的依赖,当子工程只需要用到父工程的部分依赖,而不是所有依赖时,只需要在父工程的依赖中加入<dependencyManagement></depen ...

  2. maven的父工程中添加子工程

    父工程的结构如下: 1.选中父工程名,接着单击鼠标右键,选择”Maven“ -----> "New Maven Module Project". 2.如下图,打勾 ---&g ...

  3. idea 创建maven子父工程

    1.创建maven工程: 2. 创建工程名称: 3.删除父工程下的src文件夹,指定打包方式为pom,添加maven依赖: 4.右键项目添加子工程: 5.添加子工程名称: 6.子工程创建成功: 7.依 ...

  4. maven 子父工程。。。

    子工程module 父工程 主要是注意路径问题..否则会报错---

  5. Maven继承

    继承为了消除重复,可以把pom 中很多相同的配置提取出来:如:grouptId, version 等. 在使用的时候子工程直接继承父工程的依赖版本号,子工程中不再需要指定具体版本号,方便统一管控项目的 ...

  6. 011.maven 继承与聚合

    聚合:对于聚合模块来说,它知道有哪些被聚合的模块,而对于被聚合的模块来说,它们不知道被谁聚合了,也不知道它的存在: 继承:对于继承关系的父POM来说,它不知道自己被哪些子模块继承了,对于子POM来说, ...

  7. maven(二) maven项目构建ssh工程(父工程与子模块的拆分与聚合)

    前一节我们明白了maven是个什么玩意,这一节就来讲讲他的一个重要的应用场景,也就是通过maven将一个ssh项目分割为不同的几个部分独立开发,很重要,加油 --WH 一.maven父工程与子模块的拆 ...

  8. 转帖:maven(二) maven项目构建ssh工程(父工程与子模块的拆分与聚合)

    出处:http://www.cnblogs.com/whgk/p/7121336.html 前一节我们明白了maven是个什么玩意,这一节就来讲讲他的一个重要的应用场景,也就是通过maven将一个ss ...

  9. Maven父工程

    1.创建Maven工程时 Packaging 选项为 pom 2.父工程目录结构只有pom.xml(父工程不进行编码) 3.需要的依赖信息在父工程中定义,子模块继承 5.将各个子模块聚合到一起 6.将 ...

随机推荐

  1. 带你入门Camtasia Studio录像机软件

    Camtasia软件和其他录制软件不同,不论是编辑功能还是制作功能还是其他功能方面都远远高于其他录制软件.那这边我们可以一起了解一下基础软件功能. 首先,我们在电脑端安装了软件以后,进行实际操作.在操 ...

  2. linux命令-awk,sort,uniq

    学习地址:http://man.linuxde.net/awk#awk的工作原理 awk 选项参数说明: -F fs or --field-separator fs 指定输入文件折分隔符,fs是一个字 ...

  3. 【mq读书笔记】mq消息消费

    消息消费以组的的模式开展: 一个消费组内可以包含多个消费者,每一个消费组可订阅多个主题: 消费组之间有集群模式与广播模式两种消费模式:集群模式-主题下的同一条消息只允许被其中一个消费者消费.广播模式- ...

  4. 【GDOI2014模拟】JZOJ2020年8月14日提高组 服务器

    [GDOI2014模拟]JZOJ2020年8月14日提高组 服务器 题目 Time and Memory Limits Description 我们需要将一个文件复制到n个服务器上,这些服务器的编号为 ...

  5. C++的编程指南

    序言:每天更新C++的内容 一.文件结构 每个C++/C程序通常分为两个文件.一个文件用于保存程序的声明(declaration),称为头文件.另一个文件用于保存程序的实现(implementatio ...

  6. MySQL错误日志(Error Log)

    错误日志是一个文本文件,记录了 MySQL Server 每次启动和关闭的详细信息以及运行过程中所有较为严重的警告和错误信息.在遇到问题时,应该首先查看这个文件. 如何开启 使用命令 SHOW VAR ...

  7. 部署 Prometheus 和 Grafana 到 k8s

    在 k8s 中部署 Prometheus 和 Grafana Intro 上次我们主要分享了 asp.net core 集成 prometheus,以及简单的 prometheus 使用,在实际在 k ...

  8. ERP费用报销操作与设计--开源软件诞生31

    赤龙ERP费用报销讲解--第31篇 用日志记录"开源软件"的诞生 [进入地址 点亮星星]----祈盼着一个鼓励 博主开源地址: 码云:https://gitee.com/redra ...

  9. 第4.3节 Python中与迭代相关的函数

    下面要介绍的enumerate.range.zip.reversed.sorted属于Python内置的函数或者类别,返回的对象都可通过迭代方法访问. 一.    enumerate函数 1.     ...

  10. 通俗易懂方式解说Python中repr(变量)和str(变量)函数的区别

    老猿在<Python中repr(变量)和str(变量)的返回值有什么区别和联系>介绍了repr(变量)和str(变量)的区别和联系(对应特殊方法__repr__和__str__),但老猿刚 ...