Maven高级
概念
分模块开发使得开发过程更加高效和更便于管理,将之前的三层架构的实体类分为4个模块,再用聚合的思想管理这几个分模块,这个模块只留pom文件,层次结构更加清晰易懂。
聚合
为了解决分模块更新导致其他模块不能正常运行的问题
1.创建一个模块,只存放pom文件,这个pom文件相当于管理着其他模块,指定属性为pom,标签内部指定各个分模块的名字。
<groupId>com.itheima</groupId>
<artifactId>ssm</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>../ssm_pojo</module>
<module>../ssm_dao</module>
<module>../ssm_service</module>
<module>../ssm_controller</module>
</modules>
继承
管理了各个模块jar包的版本,各个模块间的版本不一样有可能会起冲突,导致运行报错。
1.在父模块的pom文件加上jar包管理专用标签
- dependencyManagement:管理各个模块的jar包版本
<dependencyManagement>
<dependencies>
</dependencies>
</dependencyManagement>
2.在各个子模块的pom文件上方加上父模块的坐标
<parent>
<groupId>com.itheima</groupId>
<artifactId>ssm</artifactId>
<version>1.0-SNAPSHOT</version>
<!--父模块的pom文件真实路径-->
<relativePath>../ssm/pom.xml</relativePath>
</parent>
3.在父模块中定义通用的插件标签(pluginManagement)
<build>
<pluginManagement>
<!--设置插件-->
<plugins>
<!--具体的插件配置-->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>80</port>
<path>/</path>
<uriEncoding>UTF-8</uriEncoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
属性定义
在maven中定义一个通用的属性
<properties>
<spring.version>5.1.9.RELEASE</spring.version>
</properties>
使用这个通用的属性
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
内置属性
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
工程版本
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-n5sAsQ4p-1595771121945)(C:\Users\gwx\AppData\Roaming\Typora\typora-user-images\image-20200726203914676.png)]
怎样使用maven管理jdbc.properties文件内容
第一步:自定义变量,在文件中使用${}获取值
<properties>
<jdbc.url>jdbc:mysql:///ssm_demo</jdbc.url>
</properties>
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=${jdbc.url}
jdbc.username=root
jdbc.password=root
第二步:配置资源文件对应的信息
<build>
<resources>
<resource>
<directory>../ssm_dao/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
创建多环境
<!--创建多环境-->
<profiles>
<!--定义具体的环境:生产环境-->
<profile>
<id>pro_env</id>
<!--定义环境中专用的属性值-->
<properties>
<jdbc.url>jdbc:mysql:///ssm_demo</jdbc.url>
</properties>
</profile>
<!--定义具体的环境:开发环境-->
<profile>
<id>dep_env</id>
<!--定义环境中专用的属性值-->
<properties>
<jdbc.url>jdbc:mysql:///ssm2_demo</jdbc.url>
</properties>
</profile>
</profiles>
开发环境打包语法:install -P 具体使用哪个环境,写对应的Id值
默认启动:
<activation>
<activeByDefault>true</activeByDefault>
</activation>
跳过测试
图形化跳过
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wrEvfo7M-1595771121948)(C:\Users\gwx\AppData\Roaming\Typora\typora-user-images\image-20200726211259645.png)]
命令跳过测试:
mvn install -D skipTests
配置文件跳过测试:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-cdlKi0CG-1595771121951)(C:\Users\gwx\AppData\Roaming\Typora\typora-user-images\image-20200726212104656.png)]
私服
实现小范围的资源共享
Nexus:maven私服
启动服务器:nexus /run nexus,默认端口8081。
仓库分类:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4vcfXzRK-1595771121954)(C:\Users\gwx\AppData\Roaming\Typora\typora-user-images\image-20200726213131114.png)]
idea环境中资源上传与下载
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UynUyTqQ-1595771121958)(C:\Users\gwx\AppData\Roaming\Typora\typora-user-images\image-20200726213657898.png)]
71121951)]
私服
实现小范围的资源共享
Nexus:maven私服
启动服务器:nexus /run nexus,默认端口8081。
仓库分类:
[外链图片转存中…(img-4vcfXzRK-1595771121954)]
idea环境中资源上传与下载
[外链图片转存中…(img-UynUyTqQ-1595771121958)]