1.分类

(1)全局配置(project build)

针对整个项目的所有情况都有效

(2)配置(profile build)

针对不同的profile配置

  1. <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/maven-v4_0_0.xsd">
  5. <!– "Project Build" contains more elements than just the BaseBuild set –>
  6. <build>…</build>
  7. <profiles>
  8. <profile>
  9. <!– "Profile Build" contains a subset of "Project Build"s elements –>
  10. <build>…</build>
  11. </profile>
  12. </profiles>
  13. </project>

2.配置说明

       (1)基本元素

  1. <build>
  2. <defaultGoal>install</defaultGoal>
  3. <directory>${basedir}/target</directory>
  4. <finalName>${artifactId}-${version}</finalName>
  5. <filters>
  6. <filter>filters/filter1.properties</filter>
  7. </filters>
  8. ...
  9. </build>

1)defaultGoal

执行build任务时,如果没有指定目标,将使用的默认值。

如上配置:在命令行中执行mvn,则相当于执行mvn install

2)directory
                     build目标文件的存放目录,默认在${basedir}/target目录

3)finalName

build目标文件的名称,默认情况为${artifactId}-${version}

4)filter

定义*.properties文件,包含一个properties列表,该列表会应用到支持filter的resources中。

也就是说,定义在filter的文件中的name=value键值对,会在build时代替${name}值应用到resources中。

maven的默认filter文件夹为${basedir}/src/main/filters

        (2)Resources配置

用于包含或者排除某些资源文件

  1. <build>
  2. ...
  3. <resources>
  4. <resource>
  5. <targetPath>META-INF/plexus</targetPath>
  6. <filtering>false</filtering>
  7. <directory>${basedir}/src/main/plexus</directory>
  8. <includes>
  9. <include>configuration.xml</include>
  10. </includes>
  11. <excludes>
  12. <exclude>**/*.properties</exclude>
  13. </excludes>
  14. </resource>
  15. </resources>
  16. <testResources>
  17. ...
  18. </testResources>
  19. ...
  20. </build>

1)resources

一个resources元素的列表。每一个都描述与项目关联的文件是什么和在哪里

2)targetPath

指定build后的resource存放的文件夹,默认是basedir。

通常被打包在jar中的resources的目标路径是META-INF

3)filtering

true/false,表示为这个resource,filter是否激活
             4)directory

定义resource文件所在的文件夹,默认为${basedir}/src/main/resources

5)includes

指定哪些文件将被匹配,以*作为通配符

6)excludes

指定哪些文件将被忽略

7)testResources

定义和resource类似,只不过在test时使用

        (3)plugins配置

用于指定使用的插件

  1. <build>
  2. ...
  3. <plugins>
  4. <plugin>
  5. <groupId>org.apache.maven.plugins</groupId>
  6. <artifactId>maven-jar-plugin</artifactId>
  7. <version>2.0</version>
  8. <extensions>false</extensions>
  9. <inherited>true</inherited>
  10. <configuration>
  11. <classifier>test</classifier>
  12. </configuration>
  13. <dependencies>...</dependencies>
  14. <executions>...</executions>
  15. </plugin>
  16. </plugins>
  17. </build>

1)GAV

指定插件的标准坐标

2)extensions

是否加载plugin的extensions,默认为false

3)inherited

true/false,这个plugin是否应用到该pom的孩子pom,默认为true

4)configuration

配置该plugin期望得到的properties

5)dependencies

作为plugin的依赖

6)executions

plugin可以有多个目标,每一个目标都可以有一个分开的配置,可以将一个plugin绑定到不同的阶段

假如绑定antrun:run目标到verify阶段

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <artifactId>maven-antrun-plugin</artifactId>
  5. <version>1.1</version>
  6. <executions>
  7. <execution>
  8. <id>echodir</id>
  9. <goals>
  10. <goal>run</goal>
  11. </goals>
  12. <phase>verify</phase>
  13. <inherited>false</inherited>
  14. <configuration>
  15. <tasks>
  16. <echo>Build Dir: ${project.build.directory}</echo>
  17. </tasks>
  18. </configuration>
  19. </execution>
  20. </executions>
  21. </plugin>
  22. </plugins>
  23. </build>

id:标识,用于和其他execution区分。当这个阶段执行时,它将以这个形式展示[plugin:goal execution: id]。在这里为: [antrun:run execution: echodir]
                           goals:目标列表

phase:目标执行的阶段

inherit:子类pom是否继承

configuration:在指定目标下的配置

        (4)pluginManagement配置

pluginManagement的配置和plugins的配置是一样的,只是用于继承,使得可以在孩子pom中使用。

父pom:

  1. <build>
  2. ...
  3. <pluginManagement>
  4. <plugins>
  5. <plugin>
  6. <groupId>org.apache.maven.plugins</groupId>
  7. <artifactId>maven-jar-plugin</artifactId>
  8. <version>2.2</version>
  9. <executions>
  10. <execution>
  11. <id>pre-process-classes</id>
  12. <phase>compile</phase>
  13. <goals>
  14. <goal>jar</goal>
  15. </goals>
  16. <configuration>
  17. <classifier>pre-process</classifier>
  18. </configuration>
  19. </execution>
  20. </executions>
  21. </plugin>
  22. </plugins>
  23. </pluginManagement>
  24. ...
  25. </build>

则在子pom中,我们只需要配置:

  1. <build>
  2. ...
  3. <plugins>
  4. <plugin>
  5. <groupId>org.apache.maven.plugins</groupId>
  6. <artifactId>maven-jar-plugin</artifactId>
  7. </plugin>
  8. </plugins>
  9. ...
  10. </build>

这样就大大简化了孩子pom的配置

pom.xml中build标签的更多相关文章

  1. maven项目pom.xml中parent标签的使用(转)

    原文地址:https://blog.csdn.net/qq_41254677/article/details/81011681 使用maven是为了更好的帮项目管理包依赖,maven的核心就是pom. ...

  2. maven pom.xml 中各个标签元素的作用

    <groupId> : 项目或者组织的唯一标识 <artifactId>项目的通用名称 <artifactId>项目的通用名称 <version> 项目 ...

  3. Java 在pom.xml中配置build resources, 来防止我们资源导出失败问题(Maven项目)

    在pom.xml中配置build, 来防止我们资源导出失败问题 <!--在build中配置resources, 来防止我们资源导出失败问题--> <build> <res ...

  4. 刨析Maven(对pom.xml配置文件常用标签的解析)

    昨天在阿里云看到了一句话,"当你Learning和Trying之后,如果能尽量把Teaching也做好,会促进我们思考".共勉! 这是关于Maven的第三篇博客,这次我们深入了解p ...

  5. eclipse中基于maven构建的web项目pom.xml中指定的jar包无法发布到tomcat中

    eclipse运行maven web项目报错: 信息: Starting Servlet Engine: Apache Tomcat/7.0.57 一月 07, 2015 11:50:44 下午 or ...

  6. (转)如何在maven的pom.xml中添加本地jar包

    1 maven本地仓库认识 maven本地仓库中的jar目录一般分为三层:图中的1 2 3分别如下所示: 1 groupId 2 artifactId 3 version 4 jar包的依赖 如果要将 ...

  7. 在maven pom.xml中加载不同的properties ,如localhost 和 dev master等jdbc.properties 中的链接不一样

    [参考]:maven pom.xml加载不同properties配置[转] 首先 看看效果: 点开我们项目中的Maven projects 后,会发现右侧 我们profile有个可勾选选项.默认勾选l ...

  8. Maven pom.xml中的元素modules、parent、properties以及import

    前言 项目中用到了maven,而且用到的内容不像利用maven/eclipse搭建ssm(spring+spring mvc+mybatis)用的那么简单:maven的核心是pom.xml,那么我就它 ...

  9. (转)如何在maven的pom.xml中添加本地jar包

    转载自: https://www.cnblogs.com/lixuwu/p/5855031.html 1 maven本地仓库认识 maven本地仓库中的jar目录一般分为三层:图中的1 2 3分别如下 ...

随机推荐

  1. 【Hive学习之三】Hive 函数

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 hadoop-3.1.1 apache-hive-3.1.1 ...

  2. Mysql Federated For Windows

    [1]windows环境下打开federated (1)关闭.命令:mysql> net stop mysql (2)添加federated字段.在my.ini文件中添加一个字段,注意位于[my ...

  3. java运行cmd命令

    java的Runtime.getRuntime().exec(commandStr)可以调用执行cmd指令. cmd /c dir 是执行完dir命令后关闭命令窗口. cmd /k dir 是执行完d ...

  4. hive 常见时间日期函数的使用

    1.时间戳函数 日期转时间戳:从1970-01-01 00:00:00 UTC到指定时间的秒数 获得当前时区的UNIX时间戳: select unix_timestamp(); 1533716607 ...

  5. flask 文件上传(单文件上传、多文件上传)

    文件上传 在HTML中,渲染一个文件上传字段只需要将<input>标签的type属性设为file,即<input type=”file”>. 这会在浏览器中渲染成一个文件上传字 ...

  6. SpringBoot整合redis哨兵主从服务

    前提环境: 主从配置 http://www.cnblogs.com/zwcry/p/9046207.html 哨兵配置 https://www.cnblogs.com/zwcry/p/9134721. ...

  7. Mysql初级第三天(wangyun)

    1.JDBC简介 1).数据库驱动 2).SUN公司为统一数据库的操作,定义了一套Java操作数据库的规范,称之为JDBC. 3).JDBC全称:Java Database Connectivity( ...

  8. to refactor for refactor

    v1.1 if all algorithm are in one function, it will expand. so each operate type should be separated. ...

  9. Golang闭包案例分析与普通函数对比

    闭包案例 package main import ( "fmt" "strings" //记住一定引入strings包 ) //①编写一个函数makeSuffi ...

  10. Maven 工程读取resource下的文件

    1:方式1: public static List<String> userList; static { userList = new LinkedList<String>() ...