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

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

<profiles>  
     <profile>  
         <id>product</id>  
         <properties>  
             <env>product</env>  
         </properties>  
     </profile>  
</profiles>

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

<bulid><!--指定资源目录 配置是否启用资源过滤(就是是否启用占位符替换)-->  
     <resources>  
          <resource>  
              <directory>src/main/resources</directory>  
              <filtering>true</filtering>  
              <includes>  
                  <include>logback.xml</include>  
              </includes>  
          </resource>  
     </rwsources>  
     <!-- 变量来源 -->  
     <filters>  
        <filter>src/main/resources/log-profile-${env}.properties</filter>          
      </filters>  
 </build>

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

<activeProfiles>  
  <activeProfile>product</activeProfile>  
</activeProfiles>

总结:

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

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


友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信