maven高级
1 .maven的常用指令 输出错误的完整信息 , mvn clean -X package
2 .<maven.test.skip>true</maven.test.skip> 跳过测试
3.资源的复制 resources
<resources>
<resource>
在复制的资源文件中替换maven的属性值
<filtering>true</filtering>
</resource>
</resources>
4.``Maven的跳过测试的方法
-
mvn指令 -D skipTests
-
插件配置 maven-surefire-plugin
定义每个项目的父工程必须导入以下三个属性
<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>
6. maven 仓库配置ider 还是不能运行 这个解决
<repositories>
<repository>
<id>nexus</id>
<name>internal nex repository</name>
<url>http://repo.maven.apache.org/maven2</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
拆分 ssm _pojo 实体类 配置文件(无)
拆分 dao 把pojo 坐标倒过来 不能compile 成功 就把pojo install
父类模块聚合 顺序怎么改变 都是 pojo - dao - service- controller
控制层 依赖 seivice service 依赖dao dao 层依赖 实体类
模块继承
<packaging>pom</packaging>
父类用的是 聚合工程用的 pom
继承目的就是要所有的子类 jar版本同意
子类模块里边
<!--定义工程的父工程-->
<parent>
<artifactId>ssm</artifactId>
<groupId>com.itheima</groupId>
<version>1.0-SNAPSHOT</version>
<!--填写父工程的pom 文件-->
<relativePath>pom.xml</relativePath>
</parent>
父工程的 tomcat 插件 <pluginManagement>
<build>
< font color="red" 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>
子类
<build>
<!--设置插件-->
<plugins>
<!--具体的插件配置-->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<font size="3" color="red">This is some text!</font>
字体变红
直接创建父类 子类不需要定义 pom 路径 >
controller 编译错误 失败原因是以下内容要标记-*
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:ApplicationContext-*.xml</param-value>
</context-param>
还有jar 包要改成 war包
自类定义的坐标 版本 全部复制到父类
<!--声明此处进行依赖管理-->
<dependencyManagement>
<!--具体的依赖-->
<dependencies>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>ssm_dao</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>ssm_pojo</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>ssm_service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>ssm_controller</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
子类可以不用写版本
<!--导入资源文件 --><!--移动到父类里边这里不用写版本-->
<dependency>
<groupId>com.itheima</groupId>
<artifactId>ssm_pojo</artifactId>
<!-- <version>1.0-SNAPSHOT</version>-->
</dependency>
继承与聚合
作用 :聚合用于快速构建项目
继承用于快速配置
不同点: 聚合是在当前模块中配置关系 聚合可以感到参与聚合模块有哪些
继承是 在子模块中配置关系,父模块无法感知那些子模块继承了自己
属性 内置属性 调用格式 ${basedir} ${version} ${user.home}
系统属性查询方式 cmd 里边输入 mvn help:systsem
版本统一的重要性
在父类自定义属性 在这个下边定义
<modules>
<module>ssm_pojo</module>
<module>ssm_dao</module>
<module>ssm_service</module>
<module>ssm_controller</module>
</modules>
<!--定义自定义属性-->
<properties>
<spring.version>5.1.9.RELEASE</spring.version>
<junit.version>4.12</junit.version>
</properties>
用大括号{spring.version}
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
父类的1.0-SNAPSHOT 这个不可以改
<groupId>com.itheima</groupId>
<artifactId>ssm</artifactId>
<version>1.0-SNAPSHOT</version>
下边的子类${version}
<dependencies>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>ssm_dao</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>ssm_pojo</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>ssm_service</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>ssm_controller</artifactId>
<version>${version}</version>
</dependency>
版本管理 (快照版 发布版)
RELEASE 代表已经完成的版本
项目开发到进入阶段里程碑后 向团队外部发布较为 稳定的版本. 发布版本
SNAPSHOT 正在开发的版本
为方便团队成员合作,解决模块间相互依赖和实时更新的问题 快照
资源配置
三步骤
!--定义自定义属性-->
<properties>
<spring.version>5.1.9.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<jdbc.url>jdbc:mysql://192.168.72.136:3306/db002</jdbc.url>
<jdbc.username>root</jdbc.username>
<jdbc.password>root</jdbc.password>
</properties>
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=${jdbc.url}?useUnicode=true&characterEncoding=utf-8
jdbc.username=${jdbc.username}
jdbc.password=${jdbc.password}
<!--配置资源文件对应的信息-->
<resources>
<resource>
<!--资源目录-->
<directory>${project.basedir}/src/main/resources</directory>
<!--过滤-->
<filtering>true</filtering>
</resource>
</resources>
-----------------------------------------------------------------------------------
--配置test测试资源文件对应的信息-->
<testResources>
<testResource>
<!--资源目录-->
<directory>${project.basedir}/src/test/resources</directory>
<!--过滤-->
<filtering>true</filtering>
</testResource>
</testResources>
多环境配置
<!--创建多环境-->
<profiles>
<!--定义具体的环境:生产环境-->
<profile>
<!--定义环境对应的唯一名称-->
<id>pro_env</id>
<!--定义环境中专用的属性值-->
<properties>
<jdbc.url>jdbc:mysql://192.168.72.136:3306/db002</jdbc.url>
<jdbc.username>root</jdbc.username>
<jdbc.password>root</jdbc.password>
</properties>
<!--设置默认启动-->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<!--定义环境对应的唯一名称-->
<id>dep_env</id>
<!--定义环境中专用的属性值-->
<properties>
<jdbc.url>jdbc:mysql://192.168.72.136:3306/db002</jdbc.url>
<jdbc.username>root</jdbc.username>
<jdbc.password>root</jdbc.password>
</properties>
</profile>
</profiles>
新建 运行的时候输入 install -P pro_env