• 【转】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的这个配置激活还可以用到很多方面,例如开发环境用快照仓库(版本),生产用发布仓库

  • 相关阅读:
    css3 box-sizing盒模型
    数字递增组件
    设置视频水平垂直居中显示在页面上
    修改placeholder样式,兼容多个浏览器
    一款还不错的日期插件layDate
    vue-cli打包后出现 “Uncaught SyntaxError: Unexpected token <”这个错
    详谈C++虚函数表那回事(一般继承关系)
    C++多态的实现及原理详细解析
    位运算求两个数的平均值
    网页设计入门<一>
  • 原文地址:https://www.cnblogs.com/exmyth/p/7151266.html
Copyright © 2020-2023  润新知