1.什么是pom?
pom(Project Object Model,项目对象模型)定义了项目的基本信息,用于描述项目是如何构建,声明项目依赖,插件配置,仓库配置等等。
2.pom配置
- <strong><project xmlns="http://maven.apache.org/POM/4.0.0"
- 2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
- 4 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- 5 <modelVersion>4.0.0</modelVersion>
- 6
- 7 <!-- 坐标 -->
- <parent> ... </parent>
- 8 <groupId>...</groupId>
- 9 <artifactId>...</artifactId>
- 10 <version>...</version>
- 11 <packaging>...</packaging>
- <!-- 仓库依赖 -->
- 12 <dependencies>...</dependencies>
- 14 <dependencyManagement>...</dependencyManagement>
- <!-- 项目模块配置 -->
- 15 <modules>...</modules>
- <!-- 全局配置文件 -->
- 16 <properties>...</properties>
- 17
- 18 <!-- 构建过程的设置 -->
- 19 <build>...</build>
- 20 <reporting>...</reporting>
- 21
- 22 <!-- 项目信息设置 -->
- 23 <name>...</name>
- 24 <description>...</description>
- 25 <url>...</url>
- 26 <inceptionYear>...</inceptionYear>
- 27 <licenses>...</licenses>
- 28 <organization>...</organization>
- 29 <developers>...</developers>
- 30 <contributors>...</contributors>
- 31
- 32 <!-- 环境设置 -->
- 33 <issueManagement>...</issueManagement>
- 34 <ciManagement>...</ciManagement>
- 35 <mailingLists>...</mailingLists>
- 36 <scm>...</scm>
- 37 <prerequisites>...</prerequisites>
- 38 <repositories>...</repositories>
- 39 <pluginRepositories>...</pluginRepositories>
- 40 <distributionManagement>...</distributionManagement>
- 41 <profiles>...</profiles>
- 42 </project></strong>
3.pom标签详解
3.1 项目坐标标签:
- <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/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>my-project</artifactId>
- <version>1.0</version>
- <packaging>war</packaging>
- </project>
- groupId : 组织标识,例如:org.codehaus.mojo,在M2_REPO目录下,将是: org/codehaus/mojo目录。
- artifactId : 项目名称,例如:my-project,在M2_REPO目录下,将是:org/codehaus/mojo/my-project目录。
- version : 版本号,例如:1.0,在M2_REPO目录下,将是:org/codehaus/mojo/my-project/1.0目录。
- packaging : 打包的格式,可以为:pom , jar , maven-plugin , ejb , war , ear , rar , par
- modelVersion:定义pom版本号,版本号有一系列的规则
(依赖关系列表(dependency list)是POM的重要部分,也就是我们项目对jar包的管理)
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.0</version>
- <scope>test</scope>
- </dependency>
- …
- </dependencies>
- groupId , artifactId , version :引用的坐标
- scope : compile(default),provided,runtime,test,system 依赖的范围
- exclusions 需要排除的依赖的jar包
3.3 继承和聚合(子pom对父pom依赖 和 父项目对模块的依赖)
- <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/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.maven.my</groupId>
- <artifactId>${projectName}-parent</artifactId>
- <version>2.0</version>
- <!-- 定义项目有哪些子模块 -->
- <modules>
- <module>my-spring-web<module>
- <module>my-spring-service<module>
- <module>my-spring-common<module>
- <module>my-spring-dao<module>
- </modules>
- </project>
(可以帮我们指定 需要的maven插件,主要标签:Resources和Plugins
Resources:用于排除或包含某些资源文件
可以用于解决 我们部署测试和线上 服务时,资源文件配置的隔离依赖:-Ponline | -Plocal
- <build>
- <!-- 开启资源文件过滤 -->
- <resources>
- <resource>
- <directory>${project.basedir}/src/main/resources</directory>
- <filtering>true</filtering>
- </resource>
- </resources>
- </build>
- <!-- 指定资源文件路径 -->
- <profiles>
- <!--测试配置 -->
- <profile>
- <id>local</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <build>
- <filters>
- <filter>${project.basedir}/src/main/swap/local.properties</filter>
- </filters>
- </build>
- </profile>
- <!-- 线上配置 -->
- <profile>
- <id>online</id>
- <activation>
- <activeByDefault>false</activeByDefault>
- </activation>
- <build>
- <filters>
- <filter>${project.basedir}/src/main/swap/online.properties</filter>
- </filters>
- </build>
- </profile>
Plugins:设置构建的插件
- <build>
- …
- <!-- 配置maven在运行时 需要依赖的插件,我们平常可以配jetty插件或者assemebly插件等-->
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>2.0</version>
- <extensions>false</extensions>
- <inherited>true</inherited>
- <configuration>
- <classifier>test</classifier>
- </configuration>
- <dependencies>…</dependencies>
- <executions>…</executions>
- </plugin>
所有文章:
maven系列文章:
相关推荐
Maven的pom.xml配置文件详细配置说明 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=...
maven最全的配置,<!-- 父项目的坐标。如果项目中没有规定某个元素的值,那么父项目中的对应值即为项目的默认值。 坐标包括group ID,artifact ID和 -->
pom.xml配置文件,包含数据库,仓库地址配置等等
SSM框架整合jar包和maven pom.xml配置文件整合
本文主要阐述了maven build是用来干什么的,以及对build标签中各子元素配置的作用
【Maven】Maven POM配置详解 - CSDN博客1
一、Idea关联的maven本地仓库配置...三、3个可单独使用的,maven项目文件pom.xml自定义配置 pom-maven-springboot-CusConfigV1.xml pom-maven-springboot-CusConfigV2.xml pom-maven-spring-CusConfigV1不推荐使用.xml
maven的pom.xml的最详细配置,内含pom的依赖、jdk配置等
maven项目的配置POM配置文件,主要是maven项目的配置,直接从中央仓库下载内容。
该jar包功能,可以在一个properties文件里面定义jdbc.url=${url},在另一个properties文件定义具体的值,通过该jar可以获取到哪个具体的值。下载之后,自行安装到本地...具体pom.xml配置使用可以参考网络其他博文,谢谢
记录一下自己常用的maven工程的pom.xml配置详解,各个标签详解
这个一个maven web项目的pom文件。主要包含运用spring mvc, spring, mybatis 框架时需要导入的依赖列表。旨在帮助一些愿在java web上进行开发的新手。大部分依赖都有其注释与说明。
maven中pom.xml基本配置,将内容复制粘贴至pom.xml框中,点击运行即可
Maven_pom.xml常用配置解析
maven birt pom.xml 配置
pom作为项目对象模型。通过xml表示maven项目,使用pom.xml来实现。主要描述了项目:包括配置文件;开发者需要遵循的规则,缺陷管理系统,组织和licenses,项目的url,项目的依赖性,以及其他所有的项目相关因素。
maven pom 详解 maven2 比起maven1 来说,需要配置的文件少多了,主要集中在pom.xml和settings.xml中
pom的详细信息,让你更加了解pox配置文件每个属性的作用
创建的maven web项目所需要的依赖关系,每条依赖关系标注了作用和如果不加这条依赖会出现的错误,亲测可靠!
NULL 博文链接:https://crabdave.iteye.com/blog/2249408