maven

一:分模块构建工程

概述
解决软件的复杂性问题,或说降低软件的复杂性。不至于随着变大而不可控,使其可控,可维护,可扩展。
模块化是以分法治为依据。简单说就是把软件整体划分,划分后的块组成了软件。
这些块都相对独立,之间用接口通信,每个块完成一个功能,多个块组合可以完成一系列功能。
作用
提高工作效率
比如在项目a中你写一个模块,a完成后启动了项目b,在b 中就可以直接复用项目a的模块了。一个可复用的软件可以为将来节省费用,被复用的频率越高,成本就越低提高软件质量
可复用的软件总比不能复用的有更多的质量保证,因为可复用的软件在不断的复用过程中把一些bug,缺陷都很快的删除掉了,因此可复用的软件是有利于系统的可维护性
在这里插入图片描述
继承和聚合

何为继承?
继承是为了消除重复,如果将 dao、 service、 web 分开创建独立的工程则每个工程的 pom.xml文件中的内容存在重复,比如:设置编译版本、锁定spring的版本的等,可以 将这些重复的配置提取出来在父工程的pom.xml中定义
何为聚合?
项目开发通常是分组分模块开发, 每个模块开发完成要运行整个工程需要将每个模块聚 合在一起运行,比如:dao、service、web三个工程最终会打一个独立的 war 运行。
02_代码实现
A.创建父工程(mvn-parent)
a.不要骨架,打包形式为pom
b.pom.xml中锁定依赖版本


<dependencyManagement> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <!‐‐servlet‐api‐‐> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet‐api</artifactId> <version>4.0.0</version> <scope>provided</scope> </dependency> <!‐‐jsp‐api‐‐> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp‐api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency> <!‐‐spring核心jar包‐‐> <dependency> <groupId>org.springframework</groupId> <artifactId>spring‐context</artifactId> <version>5.1.8.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring‐aspects</artifactId> <version>5.1.8.RELEASE</version> </dependency> <dependency> <groupId>aopalliance</groupId> <artifactId>aopalliance</artifactId> <version>1.0</version> </dependency> <!‐‐jdbc会传递依赖tx‐‐> <dependency> <groupId>org.springframework</groupId> <artifactId>spring‐jdbc</artifactId> <version>5.1.8.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId><artifactId>spring‐test</artifactId> <version>5.1.8.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring‐web</artifactId> <version>5.1.8.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring‐webmvc</artifactId> <version>5.1.8.RELEASE</version> </dependency> <!‐‐mybatis‐‐> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.2</version> </dependency> <!‐‐整合包‐‐> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis‐spring</artifactId> <version>2.0.2</version> </dependency> <!‐‐mysql驱动包‐‐> <dependency> <groupId>mysql</groupId> <artifactId>mysql‐connector‐java</artifactId> <version>8.0.17</version> </dependency> <!‐‐c3p0‐‐> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.4</version> </dependency> <dependency> <groupId>com.mchange</groupId> <artifactId>mchange‐commons‐java</artifactId> <version>0.2.16</version> </dependency> <!‐‐jstl‐‐> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency></dependencies> </dependencyManagement> 

创建子工程(mvn-core):包含service、dao
不需要骨架,打包形式为jar
pom.xml配置数据库、spring
以mvn-parent为父工程


<!‐‐将mvn‐parent作为父工程‐‐> <parent> <groupId>com.qzw</groupId> <artifactId>mvn‐parent</artifactId> <version>1.0‐SNAPSHOT</version> </parent> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <!‐‐spring核心jar包‐‐> <dependency> <groupId>org.springframework</groupId> <artifactId>spring‐context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring‐aspects</artifactId> </dependency> <dependency> <groupId>aopalliance</groupId> <artifactId>aopalliance</artifactId> </dependency> <!‐‐jdbc会传递依赖tx‐‐> <dependency> <groupId>org.springframework</groupId> <artifactId>spring‐jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring‐test</artifactId> </dependency> <!‐‐mybatis‐‐> <dependency> <groupId>org.mybatis</groupId><artifactId>mybatis</artifactId> </dependency> <!‐‐整合包‐‐> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis‐spring</artifactId> </dependency> <!‐‐mysql驱动包‐‐> <dependency> <groupId>mysql</groupId> <artifactId>mysql‐connector‐java</artifactId> </dependency> <!‐‐c3p0‐‐> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> </dependency> <dependency> <groupId>com.mchange</groupId> <artifactId>mchange‐commons‐java</artifactId> </dependency> </dependencies> 

创建子工程(mvn-web)
需要骨架,以maven-archetype-webapp创建 pom.xml中,设置mvn-parent为父工程,依赖mvn-core工程
注意:mvn-core工程必须要安装到本地仓库!!!


<parent> <groupId>com.qzw</groupId> <artifactId>mvn‐parent</artifactId> <version>1.0‐SNAPSHOT</version> </parent> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <!‐‐servlet‐api‐‐> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet‐api</artifactId> <scope>provided</scope> </dependency> <!‐‐jsp‐api‐‐> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp‐api</artifactId> <scope>provided</scope> </dependency><dependency> <groupId>org.springframework</groupId> <artifactId>spring‐web</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring‐webmvc</artifactId> </dependency> <!‐‐jstl‐‐> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> </dependency> <!‐‐依赖mvn‐core‐‐> <dependency> <groupId>com.qzw</groupId> <artifactId>mvn‐core</artifactId> <version>1.0‐SNAPSHOT</version> </dependency> </dependencies>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值