zoukankan      html  css  js  c++  java
  • 【转】maven命令-P 参数引发的思考

    序言:

    maven 命令:clean package -Dmaven.test.skip=true -P product

    1.命令很简单是:清class文件,打包构建,跳过测试,注意最后一个 -P product,-P maven 会激活项目下的pom.xml配置的<profiles>标签下id为product

    [html] view plain copy
     
    1. <profiles>  
    2.      <profile>  
    3.          <id>product</id>  
    4.          <properties>  
    5.              <env>product</env>  
    6.          </properties>  
    7.      </profile>  
    8. </profiles>  

    2.使用占位符上面配置定义的${env}进行资源过滤

    [html] view plain copy
     
    1. <bulid><!--指定资源目录 配置是否启用资源过滤(就是是否启用占位符替换)-->  
    2.      <resources>  
    3.           <resource>  
    4.               <directory>src/main/resources</directory>  
    5.               <filtering>true</filtering>  
    6.               <includes>  
    7.                   <include>logback.xml</include>  
    8.               </includes>  
    9.           </resource>  
    10.      </rwsources>  
    11.      <!-- 变量来源 -->  
    12.      <filters>  
    13.         <filter>src/main/resources/log-profile-${env}.properties</filter>          
    14.       </filters>  
    15.  </build>  

    3.通过maven的setting设置,激活profile(第二种全局的激活方式,可以忽略,如果都使用<env>,这个的值会被覆盖)

    [html] view plain copy
     
    1. <activeProfiles>  
    2.   <activeProfile>product</activeProfile>  
    3. </activeProfiles>  

    总结:
          1.   -P 参数 配合资源过滤Filter,最终使用了 src/main/resources/log-profile-product.properties 文件
          2.  这个配置文件就是为可以使用占位符的logback.xml文件提供对应 的值

          3. 激活profile和spring的profile有点志同道合,maven的这个配置激活还可以用到很多方面,例如开发环境用快照仓库(版本),生产用发布仓库

  • 相关阅读:
    SRM146 DIV1 600
    SRM145 DIV1 1000
    SRM146 DIV1 300
    SRM145 DIV1 600
    【HTML打卡】0115 margin重叠、内联元素、css控制段落
    【HTML打卡】0114 盒模型margin、border、padding
    【HTML打卡】0113 div布局,css控制
    【HTML打卡】0112-html发展、doctype声明
    Machine Learning结课感想
    【ACM打卡】ZOJ 1045 2722 2830
  • 原文地址:https://www.cnblogs.com/exmyth/p/7151266.html
Copyright © 2011-2022 走看看