maven pom.xml中的 build说明
在Maven的pom.xml文件中,Build相关配置包含两个部分,一个是<build>,另一个是<reporting>,这里我们只介绍<build>。
1. 在Maven的pom.xml文件中,存在如下两种<build>:
- <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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- ...
- <!-- "Project Build" contains elements of the BaseBuild set and the Build set-->
- <build>...</build>
- <profiles>
- <profile>
- <!-- "Profile Build" contains elements of the BaseBuild set only -->
- <build>...</build>
- </profile>
- </profiles>
- </project>
说明:
一种<build>被称为Project Build,即是<project>的直接子元素。另一种<build>被称为Profile Build,即是<profile>的直接子元素。
Profile Build包含了基本的build元素,而Project Build还包含两个特殊的元素,即各种<...Directory>和<extensions>。
2. Profile Build和Project Build共用的基本build元素
1) 示例如下:
- <build>
- <defaultGoal>install</defaultGoal>
- <directory>${basedir}/target</directory>
- <finalName>${artifactId}-${version}</finalName>
- ...
- </build>
说明:
- defaultGoal,执行构建时默认的goal或phase,如jar:jar或者package等
- directory,构建的结果所在的路径,默认为${basedir}/target目录
- finalName,构建的最终结果的名字,该名字可能在其他plugin中被改变
2) <resources>
资源往往不是代码,无需编译,而是一些properties或XML配置文件,构建过程中会往往会将资源文件从源路径复制到指定的目标路径。
<resources>给出各个资源在Maven项目中的具体路径。示例如下:
- <build>
- ...
- <filters>
- <filter>filters/filter1.properties</filter>
- </filters>
- <resources>
- <resource>
- <targetPath>META-INF/plexus</targetPath>
- <filtering>false</filtering>
- <directory>${basedir}/src/main/plexus</directory>
- <includes>
- <include>configuration.xml</include>
- </includes>
- <excludes>
- <exclude>**/*.properties</exclude>
- </excludes>
- </resource>
- </resources>
- <testResources>
- ...
- </testResources>
- ...
- </build>
说明:
- resources,build过程中涉及的资源文件
- targetPath,资源文件的目标路径
- filtering,构建过程中是否对资源进行过滤,默认false
- directory,资源文件的路径,默认位于${basedir}/src/main/resources/目录下
- includes,一组文件名的匹配模式,被匹配的资源文件将被构建过程处理
- excludes,一组文件名的匹配模式,被匹配的资源文件将被构建过程忽略。同时被includes和excludes匹配的资源文件,将被忽略。
- filters,给出对资源文件进行过滤的属性文件的路径,默认位于${basedir}/src/main/filters/目录下。属性文件中定义若干键值对。在构建过程中,对于资源文件中出现的变量(键),将使用属性文件中该键对应的值替换。
- testResources,test过程中涉及的资源文件,默认位于${basedir}/src/test/resources/目录下。这里的资源文件不会被构建到目标构件中
3) <plugins>
<plugins>给出构建过程中所用到的插件。
- <build>
- ...
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>2.6</version>
- <extensions>false</extensions>
- <inherited>true</inherited>
- <configuration>
- <classifier>test</classifier>
- </configuration>
- <dependencies>...</dependencies>
- <executions>...</executions>
- </plugin>
- </plugins>
- </build>
说明:
- groupId
- artifactId
- version
- extensions,是否加载该插件的扩展,默认false
- inherited,该插件的configuration中的配置是否可以被(继承该POM的其他Maven项目)继承,默认true
- configuration,该插件所需要的特殊配置,在父子项目之间可以覆盖或合并
- dependencies,该插件所特有的依赖类库
- executions,该插件的某个goal(一个插件中可能包含多个goal)的执行方式。一个execution有如下设置:
- id,唯一标识
- goals,要执行的插件的goal(可以有多个),如<goal>run</goal>
- phase,插件的goal要嵌入到Maven的phase中执行,如verify
- inherited,该execution是否可被子项目继承
- configuration,该execution的其他配置参数
4) <pluginManagement>
在<build>中,<pluginManagement>与<plugins>并列,两者之间的关系类似于<dependencyManagement>与<dependencies>之间的关系。<pluginManagement>中也配置<plugin>,其配置参数与<plugins>中的<plugin>完全一致。只是,<pluginManagement>往往出现在父项目中,其中配置的<plugin>往往通用于子项目。子项目中只要在<plugins>中以<plugin>声明该插件,该插件的具体配置参数则继承自父项目中<pluginManagement>对该插件的配置,从而避免在子项目中进行重复配置。
3. Project Build特有的<...Directory>
往往配置在父项目中,供所有父子项目使用。示例如下:
- <build>
- <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
- <scriptSourceDirectory>${basedir}/src/main/scripts</scriptSourceDirectory>
- <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
- <outputDirectory>${basedir}/target/classes</outputDirectory>
- <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
- ...
- </build>
- </project>
目录可以使用绝对路径,如示例所示。如果使用相对路径,则所有的相对路径都是在${basedir}目录下。
4. Project Build特有的<extensions>
<extensions>是执行构建过程中可能用到的其他工具,在执行构建的过程中被加入到classpath中。
也可以通过<extensions>激活构建插件,从而改变构建的过程。
通常,通过<extensions>给出通用插件的一个具体实现,用于构建过程。
<extensions>的使用示例如下:
- <build>
- ...
- <extensions>
- <extension>
- <groupId>org.apache.maven.wagon</groupId>
- <artifactId>wagon-ftp</artifactId>
- <version>1.0-alpha-3</version>
- </extension>
- </extensions>
- ...
- </build>
- t;/project>
maven pom.xml中的 build说明的更多相关文章
- Java 在pom.xml中配置build resources, 来防止我们资源导出失败问题(Maven项目)
在pom.xml中配置build, 来防止我们资源导出失败问题 <!--在build中配置resources, 来防止我们资源导出失败问题--> <build> <res ...
- 在maven pom.xml中加载不同的properties ,如localhost 和 dev master等jdbc.properties 中的链接不一样
[参考]:maven pom.xml加载不同properties配置[转] 首先 看看效果: 点开我们项目中的Maven projects 后,会发现右侧 我们profile有个可勾选选项.默认勾选l ...
- Maven pom.xml中的元素modules、parent、properties以及import
前言 项目中用到了maven,而且用到的内容不像利用maven/eclipse搭建ssm(spring+spring mvc+mybatis)用的那么简单:maven的核心是pom.xml,那么我就它 ...
- Maven pom.xml中的元素modules、parent、properties以及import(转)
前言 项目中用到了maven,而且用到的内容不像利用maven/eclipse搭建ssm(spring+spring mvc+mybatis)用的那么简单:maven的核心是pom.xml,那么我就它 ...
- Maven pom.xml中添加指定的中央仓库
中央仓库就是Maven的一个默认的远程仓库,Maven的安装文件中自带了中央仓库的配置($M2_HOME/lib/maven-model-builder.jar) 在很多情况下,默认的中央仓库无法满足 ...
- [转]关于maven pom.xml中dependency type 为pom的应用
原文地址:http://blog.csdn.net/yao123long/article/details/49925659 dependency为什么会有type为pom,默认的值是什么?depend ...
- maven pom.xml 中各个标签元素的作用
<groupId> : 项目或者组织的唯一标识 <artifactId>项目的通用名称 <artifactId>项目的通用名称 <version> 项目 ...
- maven pom.xml几个特殊的插件
1. surefire插件 Maven Surefire 插件有一个 test 目标,该目标被绑定在了 test 阶段. test 目标执行项目中所有能在 src/test/java 找到的并且文件 ...
- eclipse中基于maven构建的web项目pom.xml中指定的jar包无法发布到tomcat中
eclipse运行maven web项目报错: 信息: Starting Servlet Engine: Apache Tomcat/7.0.57 一月 07, 2015 11:50:44 下午 or ...
随机推荐
- hadoop之 YARN配置参数剖析—RM与NM相关参数
参数均需要在yarn-site.xml中配置: 1. ResourceManager相关配置参数 (1) yarn.resourcemanager.address 参数解释:ResourceManag ...
- GIT-查看config配置信息
config 配置指令 1 git config config 配置有system级别 global(用户级别) 和local(当前仓库)三个 设置先从system->global->lo ...
- 微软开源rDSN分布式系统开发框架
摘要:微软亚洲研究院系统组开发的分布式系统开发框架——Robust Distributed System Nucleus(rDSN)正式在GitHub平台开源.据悉,rDSN是一个旨在为广大分布式系统 ...
- Python格式化输出%s和%d
python print格式化输出. 1. 打印字符串 print ("His name is %s"%("Aviad")) 效果: 2.打印整数 print ...
- Windows常用内容渗透命令
假设现在已经拥有一台内网[域]机器,取名X-007. 1-1.内网[域]信息收集 A.本机X-007信息收集. [+]------用户列表[Windows用户列表/邮件用户/...] ----> ...
- maven常用命令集合
作者:ydlmlh 原文:http://ydlmlh.iteye.com/blog/2158973 抽了点时间,整理了一些maven常用命令参数,以便参考:参考了maven官网和网上其他一些maven ...
- Direcshow相关资料
CCapture directshow 视频捕获类: http://blog.csdn.net/xgx198831/article/details/7284618 ICaptureGraphBuild ...
- Android开发:实时处理摄像头预览帧视频------浅析PreviewCallback,onPreviewFrame,AsyncTask的综合应用(转)
原文地址:http://blog.csdn.net/yanzi1225627/article/details/8605061# 很多时候,android摄像头模块不仅预览,拍照这么简单,而是需要在预览 ...
- App登录状态维持
转载地址:http://www.jianshu.com/p/4b6b04244773 目前APP大都支持长登录,就是用户登录一次后,如果用户没有主动注销.清除APP缓存数据或卸载APP,就在一段时间内 ...
- 【322】python控制键盘鼠标:pynput
参考:python实战===python控制键盘鼠标:pynput 参考:[Python Study Notes]pynput实现对鼠标控制 参考:pynput doc 参考:pynput Packa ...