美文网首页
二十二、Maven: Maven Profile

二十二、Maven: Maven Profile

作者: yust5273 | 来源:发表于2019-06-02 17:40 被阅读0次
1.resource目录结构准备
└─src
    ├─main
    │  ├─java
    │  │  └─com
    │  │      └─yust5273
    │  └─resources
    │      └─conf
    │          ├─dev
    │          ├─pro
    │          └─test
    └─test
        └─java
dev、pro、test 目录中分别有一个app.properties,内容分别是他们各自环境的一些配置信息,
为简化测试,这里各自的app.properties文件内容分别为,dev、pro、test
2.pom.xml相关配置如下
  <profiles>
        <profile>
            <!--不同环境Profile的唯一id-->
            <id>dev</id>
            <properties>
                <!--profiles.active是自定义的字段(名字随便起),自定义字段可以有多个-->
                <profiles.active>dev</profiles.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <profiles.active>test</profiles.active>
            </properties>
        </profile>
        <profile>
            <id>pro</id>
            <properties>
                <profiles.active>pro</profiles.active>
            </properties>
        </profile>
    </profiles>

    <build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <excludes>
                    <exclude>conf/**</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources/conf/${profiles.active}</directory>
            </resource>
        </resources>
3.运行效果

分别执行以下命令查看效果,
mvn clean install -P test
mvn clean install -P dev
mvn clean install -P pro

拓展 setting.xml中的Profile ---------家和公司两套

比如我们在公司连接公司的私服,在家里。。
就可以在setting.xml通过Profile配置不同环境。

    <profiles>
        <profile>
            <id>dev</id>
            <repositories>
                <repository>
                    <id>local-nexus</id>
                    <url>http://192.168.1.6:8081/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>plug-local-mirror</id>
                    <url>http://192.168.1.6:8081/nexus/content/groups/public/</url>
                </pluginRepository>
            </pluginRepositories>
        </profile>
        <profile>
            <id>external</id>
            <repositories>
                <repository>
                    <id>reop-mirror</id>
                    <url>http://uk.maven.org/maven2</url>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>plug-reop-mirror</id>
                    <url>http://uk.maven.org/maven2</url>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>dev</activeProfile>
    </activeProfiles>

相关文章

  • 二十二、Maven: Maven Profile

    1.resource目录结构准备 2.pom.xml相关配置如下 3.运行效果 分别执行以下命令查看效果,mvn ...

  • SpringBoot之条件注解

    背景 之前写过关于Spring和Maven的profile的区别 maven profile VS spring ...

  • maven---灵活构建(一)

    包含内容 maven属性 构建环境的差异 资源过滤 Maven Profile Web资源过滤 在profile中...

  • maven profile多环境配置

    使用maven profile实现多环境配置(代码) maven profile 实现多环境可移植构建 在开发过程...

  • Profile

    帮助命令 查看项目中哪些profile被激活了 列出当前所有profile maven属性 maven有6类属性,...

  • Maven - Profile

    什么是profile profile是在maven xml中配置的,由 包围的一块配置 profile的作用 通...

  • Maven - profile

    版权所有,未经授权,禁止转载 章节 Maven – 简介 Maven – 工作原理 Maven – Reposit...

  • maven profile

    profile 能让maven项目在不同的环境下加载不同的配置,在pom文件中加入(如果是多模块项目,加在父POM...

  • [Spring Boot 系列]集成maven和Spring b

    [Spring Boot 系列] 集成maven和Spring boot的profile 专题 maven中配置p...

  • centos7 安装 maven3.5

    下载maven 配置环境变量 vi /etc/profile source /etc/profile

网友评论

      本文标题:二十二、Maven: Maven Profile

      本文链接:https://www.haomeiwen.com/subject/fmgxxctx.html