porm文件中的build标签

porm文件中的build标签分类    (1)全局配置(projectbuild)         针对整个项目的所有情况都有效    (2)配置(profilebuild)         针对不同的profile配置[html] viewplain copyproject xm

大家好,又见面了,我是你们的朋友全栈君。

分类

       (1)全局配置(project build)

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

       (2)配置(profile build)

                 针对不同的profile配置

[html] 
view plain  
copy

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


2.配置说明

       (1)基本元素

[html] 
view plain  
copy

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

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

[html] 
view plain  
copy

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

                  用于指定使用的插件

[html] 
view plain  
copy

  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阶段

[html] 
view plain  
copy

  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:

[html] 
view plain  
copy

  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中,我们只需要配置:

[html] 
view plain  
copy

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/148826.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • cocos2d基础篇笔记四

    cocos2d基础篇笔记四

    2021年12月5日
    51
  • pandas 读取excel文件

    pandas 读取excel文件pandas读取excel文件一read_excel()的基本用法二read_excel()的常用的参数:三示例1.IO:路径2.sheet_name:指定工作表名3.header:指定标题行4.names:指定列名5.index_col:指定列索引6.skiprows:跳过指定行数的数据7.skipfooter:省略从尾部的行数据8.dtype指定某些列的数据类型pandas读取excel文件使用的是read_excel方法。本文将详细解析read_excel方法

    2025年8月10日
    3
  • NorthWind 数据库「建议收藏」

    NorthWind 数据库「建议收藏」NorthWind数据库Categories:产品类别;Customers:客户;Employees:雇员EmployeesTerritories:员工涉及领域OrderDetails:订单明细Orders:订单Products:产品Region:地区Shippers:运货商Suppliers:供应商Territories:地域    在NorthWind

    2025年8月24日
    7
  • javascript引擎PK:V8 vs Spidermonkey

    javascript引擎PK:V8 vs Spidermonkey一个月前心血来潮瞎折腾了下Nodejs,用ab和JMeter进行简单地压力测试后,不得不佩服它的速度与性能(备注:测试比较了几个框架后得出的结果)。Nodejs是什么,一个基于chrome的javascriptV8引擎的platform,特点是事件驱动,异步非阻塞IO模型,轻量。本文不是给Nodejs做广告的,它只是一个引子,关于Nodejs的具体信息大家自己google吧,这里就不多作说明了。

    2022年10月16日
    4
  • java 除法取整_java 除法运算只保留整数位的4种方式

    java 除法取整_java 除法运算只保留整数位的4种方式1.情景展示根据提供的毫秒数进行除法运算,如果将毫秒数转换成小时,小时数不为0,则只取整数位,依此类推…2.情况分析可以使用3个函数实现Math.floor(num)  只保留整数位Math.rint(num)  余数四舍五入Math.ceil(num)  取整位,再+1举例:doublenum=3.1415926;System.out.println(Math.floor…

    2022年6月5日
    116
  • 【2022年更新】手把手教你去除 WinRAR 的弹窗广告

    【2022年更新】手把手教你去除 WinRAR 的弹窗广告WinRAR作为知名的老牌压缩软件,二十余年来始终风靡全球,经久不衰。但对于中国用户,其简体中文的个人免费版安装后会有“评估版本”的标记,而且每次启动时会有代理商的弹窗广告。本文教你如何去除标记和弹窗广告,让你的WinRAR恢复纯净体验。

    2022年6月5日
    40

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号