文章目录
工具:idea
工程pom文件
1基本信息标签
1.packaging标签
packaging标签是用来规定打包类型的,
打包类型分为三种:
jar:内部调用或做为服务使用,默认为jar
pom:父类型都为pom类型
war:打包项目,用于在容器上部署
2.modelVersion标签
声明项目描述符遵循哪一个POM模型版本。模型本身的版本很少改变,虽然如此,但它仍然是必不可少的,这是为了当Maven引入了新的特性或者其他模型变更的时候,确保稳定性。
3.groupId标签
公司或者组织的唯一标志,并且配置时生成的路径也是由此生成。
4.artifactId标签
本项目的唯一ID,一个groupId下面可能多个项目,就是靠artifactId来区分的。
5.version标签
项目当前的版本号
2modules标签
用于关联子模块,一般新增子模块时,idea会自动生成引入父pom文件
3parent标签
<!--
父工程定义springboot的版本号,所有spring的依赖共用此版本,因此再使用spring的依赖时不需要添加版本
spring-boot-starter-parent中指定了很多个依赖的版本号,当我们使用spring-boot-starter-parent中的
依赖时,需要在子模块中单独的去写出需要的依赖,如果不写则不会引入。-相当于下面properties标签定义版本号
-->
<!--子工程的parent标签用于引入父工程pom -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version><!-- 2023.1.31 2.6.6版本是支持java8的稳定版本,当前支持java8的稳定版是2.7.8,可查询版本支持 -->
<relativePath /><!-- 表示父工程的pom路径,以便子工程引用 -->
</parent>
4properties标签
properties标签是用来定义一些变量,一般会定义一些版本号,然后供下方依赖版本控制或引用使用。
<properties>
<conversion>1.0</conversion>
</properties>
.......
<dependency>
<groupId>com.sq</groupId>
<artifactId>sq</artifactId>
<version>${conversion}</version>
</dependency>
5depend套系标签
dependencyManagement、dependencies、dependency标签
maven父工程的pom文件中一般要全局定义子模块中所需的依赖版本和公共依赖
定义子模块中所需依赖版本则放在dependencyManagement标签中。
注意:在dependencyManagement标签中的依赖不代表公共依赖,而仅仅是全局定义依赖的版本,子模块需要其中的依赖时,依然需要在pom文件中进行引入,只不过不需要再声明版本
其内的结构为:
<dependencyManagement>
<dependencies>
<!-- SpringBoot的依赖配置-->
<!-- 在某些情况下,我们不想或不能使用spring-boot-starter-parent。
例如,如果我们在Spring Boot项目中使用自定义父项。在这种情况下,
我们需要使用spring-boot-dependency来从依赖管理中获取资源。
但是,这个设置不允许我们使用Maven属性覆盖各个依赖项。
为了实现同样的目标,并且仍然使用不同的Tomcat版本,
我们需要在pom文件的dependencyManagement部分中添加tomcat-embed-core依赖。
需要记住的关键是,我们必须将它放在spring-boot依赖项之前。-->
<!-- <dependency>-->
<!-- <groupId>org.apache.tomcat.embed</groupId>-->
<!-- <artifactId>tomcat-embed-core</artifactId>-->
<!-- <version>9.0.44</version>-->
<!-- </dependency>-->
<!-- springboot 依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.5.14</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
要引入公共依赖,则需在dependencyManagement标签外,再通过dependencies和dependency标签引入包依赖
6exclusions标签
exclusions中的exclusion标签代表的排除,如果甲模块依赖于乙模块,而乙模块又依赖于丁,现在甲模块想依赖乙模块而不想引入丁模块,则可使用exclusion标签将丁模块排除。exclusions标签一般在dependency标签中使用
7构建设置
构建设置主要是build标签,而build标签中主要包括Resources标签和Plugins标签
7.1Resources标签-资源文件管理
Resources标签用于引用或排除资源文件
<resources>
<resource>
<!--资源的打包路径,该路径相对target/classes目录->
<targetPath>Target/plexus</targetPath>
<!--主要用来替换项目中的资源文件(* .xml、* . properties)当中的$ {…}属性值如$ {db.url}
如果filtering=true,在resources目录中存在资源文件并且配置了ws.url=com的话,在项目编译的时候,
就会自动的把pom文件中的${ws.url}替换为com->
<filtering>false</filtering>
<!--描述存放资源的目录,该路径相对POM路径->
<directory>src/main/resource</directory>
<includes> <!-- 包含的模式列表,例如**/*.xml ->
<include>**/*.yml</include>
<include>**/*.xml</include>
<include>**/*.tld</include>
<include>word/</include>
<include>excel/</include>
<include>template/</include>
</includes>
<excludes> <!-- 排除的模式列表,例如**/*.xml ->
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
7.2Plugins标签-设置构建的插件
使用情况说明:1.需要某个特殊的 jar包,但是有不能直接通过maven依赖获取,或者说在其他环境的maven仓库内不存在。
2.某个jar包内部包含的文件是我们所需要的,或者是我们希望将它提取出来放入指定的位置。
plugins 和 pluginmanagement–>dependencies 和 dependencyment,可以将这四个标签进行对比,plugins和pluginmanagement主要是管理插件和插件版本,其在build标签下,而不是project标签下。
8pom文件引入远程仓库
repositories 下的repositorie 标签用于设置远程依赖仓库,pluginRepositories 下的 pluginRepository 标签用于设置远程插件仓库
<project>
...
<repositories><!-- 设置远程依赖仓库 -->
<repository>
<id>maven-net-com</id>
<name>Maven Nt Mirror</name>
<url>http://ct.net.com/content/groups/public/</url> <!-- 仓库地址 -->
<releases> <!-- 告诉Maven是否从这个仓库下载releases版本的构件 -->
<enabled>true</enabled>
</releases>
<snapshots> <!-- 告诉Maven是否从这个仓库下载snapshots版本的构件 -->
<enabled>false</enabled><!-- 推荐false,因为snapshot构件不够稳定且不受控 -->
</snapshots>
</repository>
</repositories>
<pluginRepositories><!-- 设置远程插件仓库 -->
<pluginRepository>
<id>maven-net-cn</id>
<name>Maven China Mirror</name>
<url>http://maven.net.cn/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
...
</project>