前言:

<build >设置,主要用于编译设置

1.分类

在Maven的pom.xml文件中,存在如下两种<build>:

(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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. ...
  5. <!-- "Project Build" contains elements of the BaseBuild set and the Build set-->
  6. <build>...</build>
  7.  
  8. <profiles>
  9. <profile>
  10. <!-- "Profile Build" contains elements of the BaseBuild set only -->
  11. <build>...</build>
  12. </profile>
  13. </profiles>
  14. </project>

说明:

一种<build>被称为Project Build,即是<project>的直接子元素。

另一种<build>被称为Profile Build,即是<profile>的直接子元素。

Profile Build包含了基本的build元素,而Project Build还包含两个特殊的元素,即各种<...Directory>和<extensions>。

2. 配置说明

1.基本元素

示例如下

  1. <build>
  2. <defaultGoal>install</defaultGoal>
  3. <directory>${basedir}/target</directory>
  4. <finalName>${artifactId}-${version}</finalName>
    <filters>
    <filter>filters/filter1.properties</filter>
    </filters> 
    ...
    </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>true</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>

  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的配置

Maven build标签的更多相关文章

  1. Maven Profile标签

    Maven Profiles标签可以针对不同的环境来使用不同的配置文件 在发布的时候可以用 mvn release -p product mvn release -p test mvn release ...

  2. Maven 基础标签之版本管理和冲突解决

    前言 我们在做java项目的时候由于jar包太多,我们就需要使用maven做项目管理,管理项目的jar包依赖,包括打包上线 maven基础 Maven 是一个项目管理工具,主要用于项目构建,依赖管理, ...

  3. maven:log4j:WARN No appenders could be found for logger (loggerInfo).或者maven build error:org.apache.maven.lifecycle.LifecycleExecutionExceptio

    maven在build构建时,加载资源文件时需要配置资源文件插件: 1,在pom.xml文件中加入 <build> <finalName>${project.build.tar ...

  4. 在eclipse如何删除无效的maven build

    在Eclipse的maven项目中,点击一次“maven build...”明明没有配置,它也就会产生一个maven build,那么如何删除这些无效的配置呢?

  5. Maven Build Profiles--reference

    What is Build Profile? A Build profile is a set of configuration values which can be used to set or ...

  6. Maven Build Life Cycle--reference

    What is Build Lifecycle? A Build Lifecycle is a well defined sequence of phases which define the ord ...

  7. No compiler is provided in this environment. --Maven build失败

    今天,maven build 失败了, 遇到下面的问题 经过查找,通过这个大佬的blog(  https://blog.csdn.net/lslk9898/article/details/738367 ...

  8. Spring Boot-右键maven build成功但是直接运行main方法出错的解决方案

    1.代码就一个Controller,从官网复制过来的,如下 package com.springboot.controller; import org.springframework.boot.Spr ...

  9. 转:eclipse maven build、maven install 等区别

    原文地址:eclipse maven build.maven install 等区别

随机推荐

  1. PHP 错误日志/安全配置

    PHP 常用配置 /php/bin/php -i | head Loaded Configuration File => /php/etc/php.ini 查看php配置目录 vim /usr/ ...

  2. 介绍Web项目中用到的几款JS日历日期控件和JS文本编辑框插件

    第一款日历日期控件:layDate 官方网站:http://laydate.layui.com/ 第二款日历日期控件:my97 官方网站:http://www.my97.net/ 第三款 文本编辑器控 ...

  3. C++类中成员变量的初始化总结

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  4. HTML5堆木头游戏

    在线演示 本地下载

  5. HTML5统计图表数据初始动画

    在线演示 本地下载

  6. Java学习笔记50:JSONObject与JSONArray的使用(转)

    Java不像PHP解析和生产JSON总是一个比较痛苦的过程.但是使用JSONObject和JSONArray会让整个过程相对舒服一些. 需要依赖的包:commons-lang.jar commons- ...

  7. hdu 5920 Wool 思路

    Wool Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem D ...

  8. scala学习手记16 – scala中的static

    前面两节学了scala的对象和伴生对象,这两个在使用的时候很有些java的静态成员的意思. scala中没有静态字段和静态方法.静态成员会破坏scala所支持的完整的面向对象模型.不过可以通过伴生对象 ...

  9. 解析CEPH: 存储引擎实现之一 filestore

    Ceph作为一个高可用和强一致性的软件定义存储实现,去使用它非常重要的就是了解其内部的IO路径和存储实现.这篇文章主要介绍在IO路径中最底层的ObjectStore的实现之一FileStore. Ob ...

  10. HTML5标签学习

    <abbr> 表示一个缩写形式,比如 "Inc."."etc.".通过对缩写词语进行标记,您就能够为浏览器.拼写检查程序.翻译系统以及搜索引擎分度器 ...