ITeye博客

maven实际使用一 --之profile打包配置

Janle · 2017-04-26 20:16 · maven · 编程语言 · Markdown

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

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

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

mvn clean package -Dmaven.test.skip=true -Pdevelopment

如果觉得打包时候使用-P比较烦时候可以使用

<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中添加以下默认的配置

<settings>  
  <activeProfiles>  
    <activeProfile>development</activeProfile>  
  </activeProfiles>  
</settings>  

据说可以一次打包两个,没有试过。有兴趣的可以试试

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

评论(0)

暂无评论。

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