1. 什么是构建配置文件?
    1. 配置文件是一组配置的集合,用来设置或者覆盖Maven构建的默认设置
    2. 使用配置文件可以为不同的环境定制构建过程,例如Producation和Development环境。
  2. Profile在pom.xml文件中使用activeProfiles/profiles元素定义,并且可以用很多的方式触发
    1. Profile在构建的时候修改POM文件,并且为变量设置不同的目标环境(例如:在开发、测试、和产品环境中的数据库服务器路径)
  3. Profile的类型
    1. profile主要有三种类型
  4. Profile激活
    1. maven的profile可以通过一下几种方式进行激活
      1. 显示使用命令控制台
      2. 通过maven设置
      3. 基于环境变量(用户/系统变量)
      4. 操作系统配置(Windows family)
      5. 现存/残缺 文件
    2. profile激活示例
      1. 假定工程目录像下面这样
      2. 现在在src/main/resources目录下有三个环境配置文件
        1.  
    3. 显示Profile激活
      1. 接下来的例子当中,通过将attach maven-antrun-plugin:run目标添加到测试阶段中,这样可以在我们的不同的Profile中输出文本信息。
      2. 我们通过使用pom.xml来定义不同的Profile,并在命令行窗口中使用maven命令进行激活Profile
      3. 假定有一下的文件
        1. <project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
          http://maven.apache.org/xsd/maven-4.0.0.xsd">
          <modelVersion>4.0.0</modelVersion>
          <groupId>com.companyname.projectgroup</groupId>
          <artifactId>project</artifactId>
          <version>1.0</version>
          <profiles>
          <profile>
          <id>test</id>
          <build>
          <plugins>
          <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.1</version>
          <executions>
          <execution>
          <phase>test</phase>
          <goals>
          <goal>run</goal>
          </goals>
          <configuration>
          <tasks>
          <echo>Using env.test.properties</echo>
          <copy file="src/main/resources/env.test.propertiestofile
          ="${project.build.outputDirectory}/env.properties"/>
          </tasks>
          </configuration>
          </execution>
          </executions>
          </plugin>
          </plugins>
          </build>
          </profile>
          </profiles>
          </project>
        2. 假定有以上文件,在控制台跳转到文件所在路径,然后执行一下命令
          1. mvn test -Ptest
          2. Maven 将会显示并且test  Profile的结果
    4. 现在我们练习一下可以按照接下来的步骤这么做
      1. 在pom.xml文件的profiles元素中添加一个profile元素(拷贝已有的profile元素并粘贴到profiles元素的结尾)
      2. 将此profile元素的id从test改为normal
      3. 将任务部分修改为echo env.properties以及copy env.properties到目标目录
      4. 再次重复以上三个步骤,修改id为prod,修改task部分为env.prod.properties
      5. 全部就是这些了,现在有了三个构建配置文件(normal/test/prod)
        1. 在命令行窗口,跳转到pom.xml所在目录,执行以下的mvn命令,使用-P选项来指定profile的名称
        2. mvn test -Pnormal
          mvn test -Pprod
        3. 检查构建的输出有什么不同!
    5. 通过Maven设置激活Profile
      1. 打开maven的setting.xml文件,该文件可以在%USER_HOME%/.m2目录下面找到,
      2. 如果setting.xml不存在,则需要创建一个
      3. 在下面的例子当中,使用activeProfiles节点添加test配置作为激活Profile
        1. <settings xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
          http://maven.apache.org/xsd/settings-1.0.0.xsd">
          <mirrors>
          <mirror>
          <id>maven.dev.snaponglobal.com</id>
          <name>Internal Artifactory Maven repository</name>
          <url>http://repo1.maven.org/maven2/</url>
          <mirrorOf>*</mirrorOf>
          </mirror>
          </mirrors>
          <activeProfiles>
          <activeProfile>test</activeProfile>
          </activeProfiles>
          </settings>
        2. 命令行控制台,跳转到pom.xml文件所在的目录,并且执行以下的mvn命令,不要使用-P选项指定Profile的名称
          1. Maven将显示被激活的test Profile的结果
          2. mvn test
    6. 通过环境激活Profile
      1. 现在从maven的setting.xml文件中删除激活的Profile,并且更新pom.xml中的test Profile,将下面的内容添加到profile元素的activation元素中
      2. 当系统属性env被设置成“test”的时候,test配置将会被触发,创建一个环境变量“env”并设置他的值为“test”
        1. <profile>
          <id>test</id>
          <activation>
          <property>
          <name>env</name>
          <value>test</value>
          </property>
          </activation>
          </profile>
      3. 打开控制台窗口,跳转到pom.xml文件所在的目录,并且执行一下的mvn命令
      4. mvn test
    7. 通过操作系统激活Profile
      1. activation元素包含下面的操作系统的信息
      2. 当系统为WindowsXP的时候,test Profile文件会触发
      3. <profile>
        <id>test</id>
        <activation>
        <os>
        <name>Windows XP</name>
        <family>Windows</family>
        <arch>x86</arch>
        <version>5.1.2600</version>
        </os>
        </activation>
        </profile>
      4. 现在控制台跳转到pom.xml所在的目录,并且执行以下的mvn命令。不要使用-P选项指定profile 的名称,Maven将显示被激活的test Profile的结果
      5. mvn  test



5、Maven-构建配置文件的更多相关文章

  1. Maven 构建配置文件

    什么是构建配置文件? 生成配置文件是一组可以用来设置或覆盖 Maven 构建配置值的默认值.使用生成配置文件,你可以针对不同的环境,如:生产V/S开发环境自定义构建. 配置文件中指定 pom.xml ...

  2. Maven学习(十四)-----Maven 构建配置文件

    Maven 构建配置文件 什么是构建配置文件? 生成配置文件是一组可以用来设置或覆盖 Maven 构建配置值的默认值.使用生成配置文件,你可以针对不同的环境,如:生产V/S开发环境自定义构建. 配置文 ...

  3. Java-Maven-Runoob:Maven 构建配置文件

    ylbtech-Java-Maven-Runoob:Maven 构建配置文件 1.返回顶部 1. Maven 构建配置文件 构建配置文件是一系列的配置项的值,可以用来设置或者覆盖 Maven 构建默认 ...

  4. 【第五篇】-Maven 构建配置文件之Spring Cloud直播商城 b2b2c电子商务技术总结

    Maven 构建配置文件 构建配置文件是一系列的配置项的值,可以用来设置或者覆盖 Maven 构建默认值. 使用构建配置文件,你可以为不同的环境,比如说生产环境(Production)和开发(Deve ...

  5. maven 学习---Maven 构建配置文件

    什么是构建配置文件? 构建配置文件是一组配置的集合,用来设置或者覆盖 Maven 构建的默认配置.使用构建配置文件,可以为不同的环境定制构建过程,例如 Producation 和 Developmen ...

  6. 01 Maven构建的项目中,把.xml等配置文件添加到编译目录

    Maven构建的项目,默认只会把src/main/resources目录下的xml配置文件添加到编译目录. 如果需要把src/main/java目录下的xml配置文件也添加到编译目录,需要在pom.x ...

  7. Maven的构建配置文件(Build Profiles)

    在命令行使用构建配置文件时,是-P,比如:mvn -Pinput 注意:这里的构建配置文件并不是一个真正的文件,而是通过指定参数来做特定的事. 以下内容引用自https://ayayui.gitboo ...

  8. 使用IntelliJ IDEA和Maven构建Java web项目并打包部署

    爱编程爱分享,原创文章,转载请注明出处,谢谢! http://www.cnblogs.com/fozero/p/6120375.html 一.背景 现在越来越多的人使用IntelliJ IDEA工具进 ...

  9. Maven学习3-使用Maven构建项目

    转自:http://www.cnblogs.com/xdp-gacl/p/4240930.html maven作为一个高度自动化构建工具,本身提供了构建项目的功能,下面就来体验一下使用maven构建项 ...

  10. Maven学习总结(三)——使用Maven构建项目

    maven作为一个高度自动化构建工具,本身提供了构建项目的功能,下面就来体验一下使用maven构建项目的过程. 一.构建Java项目 1.1.创建Java Project 1.使用mvn archet ...

随机推荐

  1. VNCserver 安装 及 oracle过程总结

    一.安装桌面系统 1.命令   yum grouplist ---列举系统中以组安装的包(组安装的包会包括很多,组安装一下就就可以安装很多附在的包.) 2.  yum groupinstall &qu ...

  2. C#String类型转换成Brush类型

    C#String类型转换成Brush类型: using System.Windows.Media; BrushConverter brushConverter = new BrushConverter ...

  3. hyper-v 80070057

    微软官网搜索MediaCreation tool进行升级.

  4. vue-cli的版本查看及vue2.x和vue3.0的区别

    链接:https://www.cnblogs.com/wyongz/p/11505048.html 链接2:https://blog.csdn.net/weixin_37745913/article/ ...

  5. 2019牛客多校第四场J free 最短路

    free 题意 给出一个带权联通无向图,你需要从s走到t,你可以选择k条变让他们的权值为0问从s到t的最小权值是多少? 分析 思考一下,如果不带k条白嫖这个条件,那么这就是一个简单的dji就搞定了,我 ...

  6. EAC3 spectral extension原理

    1.Spectral extension简介 Spectral extension是通过低频的transform coefficients合成高频transform coefficients的过程. ...

  7. AC3 overview

    1.AC3 encode overview AC3 encoder的框图如下: AC3在频域采用粗量化(coarsely quantizing)来获取较高的压缩率. 1).输入PCM 经过MDCT变换 ...

  8. Linux 中查看可用的网络接口

    目录 Linux 中查看可用的网络接口 在 Linux 中找到可用的网络接口 title: Linux 中查看可用的网络接口 date: 2020/2/25 16:56:36 toc: true -- ...

  9. redis常用配置参数

    首先弄清楚当前redis读取的是哪个配置文件,然后去配置文件修改,例如windows 打开服务列表,点击Redis,右键属性 "D:\Program Files\Redis\redis-se ...

  10. AcWing 867. 分解质因数

    #include <iostream> #include <algorithm> using namespace std; void divide(int x) { ; i & ...