---
title: "maven命令-P 参数"
author: "wangyanlong0107"
date: "2017-03-22T09:12:46Z"
tags: []
categories: ["开源软件"]
slug: "maven-p"
draft: false
lastmod: "2017-03-22T09:12:46Z"
id: 2364646
url: "https://bigdragon.iteye.com/blog/2364646"
---

# 序言：

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

 

1.命令很简单是：清class文件，打包构建，跳过[测试](http://lib.csdn.net/base/softwaretest "软件测试知识库")，注意最后一个 -P product，-P maven 会激活项目下的pom.xml配置的&lt;profiles&gt;标签下id为product

 

**\[html]** [view plain](http://blog.csdn.net/haiyuntai/article/details/53260191 "view plain") [copy](http://blog.csdn.net/haiyuntai/article/details/53260191 "copy")

 

1. &lt;profiles&gt;
2. &lt;profile&gt;
3. &lt;id&gt;product&lt;/id&gt;
4. &lt;properties&gt;
5. &lt;env&gt;product&lt;/env&gt;
6. &lt;/properties&gt;
7. &lt;/profile&gt;
8. &lt;/profiles&gt;

 

 

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

 

**\[html]** [view plain](http://blog.csdn.net/haiyuntai/article/details/53260191 "view plain") [copy](http://blog.csdn.net/haiyuntai/article/details/53260191 "copy")

 

01. &lt;bulid&gt;&lt;!--指定资源目录 配置是否启用资源过滤（就是是否启用占位符替换）--&gt;
02. &lt;resources&gt;
03. &lt;resource&gt;
04. &lt;directory&gt;src/main/resources&lt;/directory&gt;
05. &lt;filtering&gt;true&lt;/filtering&gt;
06. &lt;includes&gt;
07. &lt;include&gt;logback.xml&lt;/include&gt;
08. &lt;/includes&gt;
09. &lt;/resource&gt;
10. &lt;/rwsources&gt;
11. &lt;!-- 变量来源 --&gt;
12. &lt;filters&gt;
13. &lt;filter&gt;src/main/resources/log-profile-${env}.properties&lt;/filter&gt;
14. &lt;/filters&gt;
15. &lt;/build&gt;

 

 

3.通过maven的setting设置，激活profile（第二种全局的激活方式，可以忽略，如果都使用&lt;env&gt;，这个的值会被覆盖）

 

**\[html]** [view plain](http://blog.csdn.net/haiyuntai/article/details/53260191 "view plain") [copy](http://blog.csdn.net/haiyuntai/article/details/53260191 "copy")

 

1. &lt;activeProfiles&gt;
2. &lt;activeProfile&gt;product&lt;/activeProfile&gt;
3. &lt;/activeProfiles&gt;

 

 

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

      3. 激活profile和[spring](http://lib.csdn.net/base/javaee "Java EE知识库")的profile有点志同道合，maven的这个配置激活还可以用到很多方面，例如开发环境用快照仓库（版本），生产用发布仓库