前言:

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

1.分类

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

(1)全局配置(project build)

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

(2)配置(profile build)

针对不同的profile配置

<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. 配置说明

1.基本元素

示例如下

<build>
<defaultGoal>install</defaultGoal>
<directory>${basedir}/target</directory>
<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配置

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

<build>
...
<resources>
<resource>
<targetPath>META-INF/plexus</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/plexus</directory>
<includes>
<include>configuration.xml</include>
</includes>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
<testResources>
...
</testResources>
...
</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配置

用于指定使用的插件

<build>
...
<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>
</plugins>
</build>

  4  pluginManagement配置

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

父pom:

<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>pre-process-classes</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>pre-process</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
...
</build>

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

<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
...
</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. 会话控制Cookie的应用

    Cookie是一种由服务器发送给客户端的片段信息,存储在客户端浏览器的内存或者硬盘上,在客户端对服务器的请求中发回它.PHP透明地支持HTTP Cookie.可以利用他在远程浏览器端存储数据并以此来跟 ...

  2. unidbnavigator提示汉化

  3. mysql 一些属性

    1)定义id,设置int,涉及的属性有: BINARY二进制 UNSIGNED无符号数 UNSIGNED ZEROFILL 在列字段中使用UNSIGNED ZEROFILL属性,如: 插入int(4) ...

  4. windchill系统——开发_菜单栏添加选项(模型添加action)

    目录:C:\ptc\Windchill_11.0\Windchill\codebase\config\actions 文件:custom-actionModels.xml和custom-actions ...

  5. Java中的逻辑运算符

    逻辑运算符主要用于进行逻辑运算.Java 中常用的逻辑运算符如下表所示: 我们可以从“投票选举”的角度理解逻辑运算符: 1. 与:要求所有人都投票同意,才能通过某议题 2. 或:只要求一个人投票同意就 ...

  6. Win7.还原默认打开方式

    1.win7还原默认打开方式_百度知道.html(https://zhidao.baidu.com/question/1668708948433912307.html) Windows7:[47]打开 ...

  7. Entity Framework 6:专家版本

    随着 Entity Framework 最新主版本 EF6 的推出,Microsoft 对象关系映射 (ORM) 工具达到了新的专业高度,与久负盛名的 .NET ORM 工具相比已不再是门外汉. EF ...

  8. js进阶---12-11、jquery如何给动态创建出来的元素绑定事件

    js进阶---12-11.jquery如何给动态创建出来的元素绑定事件 一.总结 一句话总结:通过事件委托的方式,通过on方法 1.on方法在事件绑定的时候,data方式带额外参数时,字符串参数和其它 ...

  9. 音悦台mv视频下载

    需要获取的页面: 参考了此处,做了修改,代码如下: #coding:utf-8 import urllib2 import urllib import re import sys import os ...

  10. day5-configparser模块

    一.概述 在软件开发过程中,很多时候需要处理配置文件的读取解析和改写,在python中专门处理配置文件的模块就是configpaser了.顾名思义,configpaser就是配置解析器,可用来对符合格 ...