---
title: "maven实际使用一 --之profile打包配置"
author: "Janle"
date: "2017-04-26T20:16:29Z"
tags: []
categories: ["编程语言"]
slug: "maven-profile"
draft: false
lastmod: "2017-04-26T20:20:33Z"
id: 2371392
url: "https://janle.iteye.com/blog/2371392"
---

在项目的web环境或者需要打包对应不同的环境我们使用profiles区别是打包测试环境的包还是生产环境的，这里我说一下maven打包时候的配置

```java
<profiles>
   <profile>
     <id>production</id>
     <properties>
        <p1>值</p1>
     </properties>
   </profile>
   <profile>
     <id>development</id>
     <properties>
        <p1>值</p1>
     </properties>
   </profile>
</profiles>

```

类似与配置的properties文件。只不过这个是在打包时候动态加载的数据
在maven打包时候我们需要指定打包的profile，需要添加-P参数

```java
mvn clean package -Dmaven.test.skip=true -Pdevelopment
```

如果觉得打包时候使用-P比较烦时候可以使用

```java
<profiles>
   <profile>
     <id>production</id>
     <properties>
        <p1>值</p1>
     </properties>
   </profile>
   <profile>
     <id>development</id>
     <properties>
        <p1>值</p1>
     </properties>
     <activation>  
      //添加对应默认的配置
      <activeByDefault>true</activeByDefault>  
     </activation>  
   </profile>
</profiles>

```

还有一种方式可以指定或者是默认想打包那个可以在settings中添加以下默认的配置

```java
<settings>  
  <activeProfiles>  
    <activeProfile>development</activeProfile>  
  </activeProfiles>  
</settings>  
```

据说可以一次打包两个，没有试过。有兴趣的可以试试

```java
mvn -P development,test clean install 同时执行development和test两个profile
```