Maven Pom文件详解
Pom全称Project Object Model(工程对象模型)。Pom文件是Maven运行的基础,其中详细描述了一些详细的工程配置信息。
Pom文件分类
默认Pom文件内容
<project><modelVersion>4.0.0</modelVersion><repositories><repository><id>central</id><name>Central Repository</name><url>https://repo.maven.apache.org/maven2</url><layout>default</layout><snapshots><enabled>false</enabled></snapshots></repository></repositories><pluginRepositories><pluginRepository><id>central</id><name>Central Repository</name><url>https://repo.maven.apache.org/maven2</url><layout>default</layout><snapshots><enabled>false</enabled></snapshots><releases><updatePolicy>never</updatePolicy></releases></pluginRepository></pluginRepositories><build><directory>${project.basedir}/target</directory><outputDirectory>${project.build.directory}/classes</outputDirectory><finalName>${project.artifactId}-${project.version}</finalName><testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory><sourceDirectory>${project.basedir}/src/main/java</sourceDirectory><scriptSourceDirectory>${project.basedir}/src/main/scripts</scriptSourceDirectory><testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory><resources><resource><directory>${project.basedir}/src/main/resources</directory></resource></resources><testResources><testResource><directory>${project.basedir}/src/test/resources</directory></testResource></testResources><pluginManagement><!-- NOTE: These plugins will be removed from future versions of the super POM --><!-- They are kept for the moment as they are very unlikely to conflict with lifecycle mappings (MNG-4453) --><plugins><plugin><artifactId>maven-antrun-plugin</artifactId><version>1.3</version></plugin><plugin><artifactId>maven-assembly-plugin</artifactId><version>2.2-beta-5</version></plugin><plugin><artifactId>maven-dependency-plugin</artifactId><version>2.8</version></plugin><plugin><artifactId>maven-release-plugin</artifactId><version>2.5.3</version></plugin></plugins></pluginManagement></build><reporting><outputDirectory>${project.build.directory}/site</outputDirectory></reporting><profiles><!-- NOTE: The release profile will be removed from future versions of the super POM --><profile><id>release-profile</id><activation><property><name>performRelease</name><value>true</value></property></activation><build><plugins><plugin><inherited>true</inherited><artifactId>maven-source-plugin</artifactId><executions><execution><id>attach-sources</id><goals><goal>jar-no-fork</goal></goals></execution></executions></plugin><plugin><inherited>true</inherited><artifactId>maven-javadoc-plugin</artifactId><executions><execution><id>attach-javadocs</id><goals><goal>jar</goal></goals></execution></executions></plugin><plugin><inherited>true</inherited><artifactId>maven-deploy-plugin</artifactId><configuration><updateReleaseInfo>true</updateReleaseInfo></configuration></plugin></plugins></build></profile></profiles></project>
最小规格Pom文件
<modelVersion>4.0.0</modelVersion><groupId>com.mycompany.app</groupId><artifactId>my-app</artifactId><version>1</version>
</project>
子工程继承父工程pom配置值
|-- my-module| `-- pom.xml`-- pom.xml
子pom文件内容
<project><modelVersion>4.0.0</modelVersion><parent><groupId>com.mycompany.app</groupId><artifactId>my-app</artifactId><version>1</version></parent><groupId>com.mycompany.app</groupId><artifactId>my-module</artifactId><version>1</version>
</project>
Noting:
子pom文件中的version、groupId等属性可以从父目录的pom文件中继承。
因此,子pom文件中的version、groupId标签可以删除,默认继承父级pom文件中的配置。
项目聚合Pom
父子目录结构如下
|-- my-module| `-- pom.xml`-- parent`-- pom.xml
父级pom指定子模块pom文件位置:
<project><modelVersion>4.0.0</modelVersion><groupId>com.mycompany.app</groupId><artifactId>my-app</artifactId><version>1</version><packaging>pom</packaging><modules><module>../my-module</module></modules>
</project>
子pom文件配置指定父pom文件位置:
<project><modelVersion>4.0.0</modelVersion><parent><groupId>com.mycompany.app</groupId><artifactId>my-app</artifactId><version>1</version><relativePath>../parent/pom.xml</relativePath></parent><artifactId>my-module</artifactId>
</project>
Noting:通过relativePath标签指定子pom文件相对父pom文件所在位置。
Pom文件中定义共用变量
通过占位符<version>${project.version}</version>获取实际值。
pom中定义属性:
<properties><mavenVersion>3.0</mavenVersion></properties>
pom中通过占位符获取属性值:
<dependency><groupId>org.apache.maven</groupId><artifactId>maven-core</artifactId><version>${mavenVersion}</version></dependency>
通过占位符直接获取项目配置:
${project.groupId},
${project.version},
${project.build.sourceDirectory}
Maven Pom文件详解相关推荐
- 【转载】Maven pom文件详解
什么是pom? pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述了项目:包括配置文件:开发者需要遵循的规则,缺陷管理系统,组织和licenses,项目的 ...
- Maven中pom文件详解
在IDE中使用Maven IDE工具 MyEclipse 集成maven插件 Eclipse Eclipse For Java EE IDEA 集成Maven插件 在IDE中 配置Maven 指定 ...
- java中pom文件详解
目录 一.maven项目的目录结构 二.根元素和必要配置 三.父项目和parent元素 四.项目构建需要的信息 1.路径管理 2.资源管理 3.插件管理 4.构建扩展 5.其他配置 五.项目依赖相关信 ...
- maven(二)pom文件详解
文章目录 1. 什么是pom 文件? 2. pom文件各常用属性含义 2.1 项目基本信息 2.2 build项目构建属性介绍 2.2.1 resources资源路径列表 2.2.2 plugins ...
- 【Maven】Maven POM配置详解
就像web项目的核心是web.xml一样,Maven项目的核心是pom.xml,POM(project object model,项目对象模型)定义了项目的基本信息,用于描述项目如何构建,如何声明依赖 ...
- maven pom.xml详解
什么是pom? pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述了项目:包括配置文件:开发者需要遵循的规则,缺陷管理系统,组织和licenses,项目的 ...
- springboot中pom文件详解
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...
- Maven的pom.xml文件详解------The Basics
转载自 Maven的pom.xml文件详解------The Basics Maven坐标 GroupId.artifactId和version构成了Maven的坐标(groupId和version ...
- Maven的pom.xml文件详解------Environment Settings
转载自 Maven的pom.xml文件详解------Environment Settings Issue Management 使用的缺陷跟踪系统(Bugzilla,TestTrack,Clear ...
- Maven的pom.xml文件详解------Build Settings
转载自 Maven的pom.xml文件详解------Build Settings 根据POM 4.0.0 XSD,build元素概念性的划分为两个部分:BaseBuild(包含poject bui ...
最新文章
- EditPlus 格式化HTML JS CSS
- 防止删库悲剧发生,这里有个Bash脚本测试框架,危险代码一测便知
- 小卡片遇热就变机器人,不插电就能运动,哈佛加州理工新研究登上Nature子刊...
- Node.js和NoSQL开发比特币加密货币应用程序(下)
- java 二分法 应用_介绍一下java中的二分法运用
- Docker操作命令详解
- Hibernate提供的内置标识符生成器
- 深度学习(四十五)——Stack GAN, GAN Ensemble, Pix2Pix, CycleGAN
- ajax与java交互实例,1、Ajax与Java通过GET方式交互
- Boxee智能电视机顶盒在美国CES亮相
- 大数据量下高并发同步
- i print打印监控系统
- android 服务自动运行怎么办,Android服务开机自动运行
- C++核心准则​Pro.bounds:边界安全群组
- STC51控制的超声波HY-SRF05测距、红外接收小车代码
- 用卡尔曼滤波器跟踪导弹(量测更新频率与时间更新频率不相等)
- Too many re-renders. React limits the number of renders to prevent an infinite loop
- 机械键盘知识漫谈(一)- 初级篇
- mysql数据库中针对结果保留小数的问题
- IntelliJ IDEA优化