ITeye博客

maven命令-P 参数

wangyanlong0107 · 2017-03-22 09:12 · maven · 开源软件 · Markdown

序言:

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。