pom文件的作用和其中各个属性的作用
pom指的是project object model(项目对象模型),pom文件是Maven项目的工作基本单元,描述了项目的所有必要信息,使Maven能自动化得构建项目,定义项目的基本信息,主要用于管理:源代码、配置文件、开发者的信息和角色、问题追踪系统、组织信息、项目授权、项目的url、项目的依赖关系等等。。
那什么是Maven?
- Maven 是专门用于构建和管理Java相关项目的管理工具。主要作用是jar管理和工程打包
POM之间的关系,继承、聚合与依赖
继承:子项目继承父项目的pom.xml,在子项目中定义父项目。
依赖:一个dependency元素定义一个依赖关系
聚合:聚合和关联多个项目中相同的配置,在被聚合项目中定义其子模块
以使用${propertyName}的形式引用属性
#指定xml版本和编码方式
<?xml version="1.0" encoding="UTF-8"?>
<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">
#模型版本号
<modelVersion>4.0.0</modelVersion>
pom中
使用groupdId+artifactId+version的形式来唯一确定一个项目
groupdId:项目的组织标识符,通常是公司的域名反转形式
artifactId:项目的唯一标识符,通常是项目名称
version:项目版本,0.0.1-SNAPSHOT 表示这是一个正在开发中的快照版本
1.打包方式packaging
#packaging:定义 Maven 项目的打包方式,有 JAR 、WAR 和 pom 三种格式,JAR作为项目依赖,pom打出来可以作为其他项目的maven依赖,父工程中使用;war是WEB项目
<packaging>pom</packaging>
2.parent引入父项目
#被继承父类的相关信息
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
3.父项目添加子项目modules
#在父maven文件中添加子maven模块
<modules>
<module>user-service</module>
</modules>
4.版本定义成变量,供依赖模块引用
#该标签相对于定义一个变量为标签值,内容可以修改,在pom文件中可以通过${标签 }表示其内容,当版本号发生改变时,只有更新properties标签中的变量就行了,不用更新所有依赖的版本号
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
<mysql.version>5.1.34</mysql.version>
<druid.version>1.1.10</druid.version>
<junit.version>4.1.2</junit.version>
<lombok.version>1.16.10</lombok.version>
<log4j.vsrsion>1.2.17</log4j.vsrsion>
<springboot.version>2.1.4.RELEASE</springboot.version>
<spring-cloud-alibaba.version>2.1.2.RELEASE</spring-cloud-alibaba.version>
</properties>
5.dependencies 项目依赖

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
6.dependencyManagement

<dependencyManagement>
<dependencies>
<!-- springcloud的依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- springboot的依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<!-- <version>2.1.4.RELEASE</version>-->
<version>${springboot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- 工具包-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
</dependencyManagement>
7.build项目打包
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springboot.version}</version>
</plugin>
</plugins>
</build>
- sd
浙公网安备 33010602011771号