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 ...
随机推荐
- 根据tomcat的日志判断web的发布路径以及服务路径
[ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.unde ...
- php日志函数error_log
php内置打印log日志的函数,这个对php程序调试非常高效 1.配置 编辑php.ini文件 log_errors = On 设置log日志存储路径 error_log = /wwwroot/php ...
- 【python】使用Python中的urlparse、urllib抓取和解析网页
一.解析URL 函数urlparse(urlstring [, default_scheme [, allow_fragments]])的作用是将URL分解成不同的组成部分,它从urlstring中取 ...
- 再记录一次delete出错的经历
调试的时候进行到delete语句时出现问题,我做的操作是在函数体内用int*申请了N个内存空间,这让我十分纳闷,为什么不能delete呢? 回忆到之前delete出错也遇过一次问题 手动封装OpenC ...
- Mysql8.0 Public Key Retrieval is not allow错误的解决办法
在使用Mysql 8.0时重启后启动项目的事后会报错com.mysql.jdbc.exceptions.jdbc4.MysqlNonTransientConnectionException: Publ ...
- ubuntu安装了mysql 但是编译报错 mysql.h: No such file or directory
在Ubuntu体系中,已经安装了mysql,即应用sudo apt-get install mysql-server mysql-client 但是用C编译mysql数据库时,报错fatal erro ...
- C#调用Oracle带输出数据集的存储过程
1.创建一个带输出数据集的Oracle存储过程 create or replace procedure PRO_test(in_top in number,cur_out out sys_refcur ...
- modelsim 仿真xilinx fir ip
到现在不管fir ip 用的对不对,但是在使用modelsim是可以仿真fir ip的. 具体步骤: 1.仿真库,添加到modelsim目录配置文件: 2.将这个文件中的: :List of dyna ...
- thinkphp5中Indirect modification of overloaded element of XXX has no effect的解决办法
最近在使用Thinkphp5做foreach循环嵌套的时候报错:Indirect modification of overloaded element of XXX has no effect,网上搜 ...
- springboot 默认错误处理--自定义
1.在resoures下创建resoures/error文件夹 在其中自定义:404.html 403.html 500.html