美文网首页
maven多环境打包配置

maven多环境打包配置

作者: 我的昵称就是昵称 | 来源:发表于2020-07-08 11:13 被阅读0次

1.在resources 目录中创建不同的项目启动配置文件。

resources目录结构如图:


image.png

2.修改项目pom.xml文件,build中添加打包时使用的配置。

build中添加的内如格式如下:

 <build>
      <!--项目生成的包名称-->
        <finalName>/demo</finalName>
        <!--本地使用maven install命令打包时需要注释掉start-->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
               <!-- 资源根目录排除各环境的配置,防止在生成目录中多余其它目录 -->
                <excludes>
                    <exclude>**/env/dev/**</exclude>
                    <exclude>**/env/test/**</exclude>
                    <exclude>**/env/prod/**</exclude>
                </excludes>
             <!-- resources目录下需要保留的文件 -->
                <includes>
                    <include>**/processes/**</include>
                    <include>**/static/**</include>
                    <include>**/templates/**</include>
                    <include>**/*.json</include>
                </includes>
            </resource>
            <resource>
                <!-- 指定使用配置文件的根目录 -->
                <directory>src/main/resources/env/${activeProfile}</directory>
                <includes>
                    <include>*.yml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
        <!--本地使用Idea install命令打包时需要注释掉end-->
        <plugins>
             <!--maven 打包插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.0</version>
            </plugin>
        </plugins>
    </build>
<!--本地使用maven install命令打包时需要注释掉start-->
    <profiles>
        <!--开发环境 -->
        <profile>
            <id>dev</id>
            <properties>
                <activeProfile>dev</activeProfile>
            </properties>
            <activation>
             <!--是否默认使用该配置文件 -->
                <activeByDefault>false</activeByDefault>
            </activation>
        </profile>
        <!--测试环境 -->
        <profile>
            <id>test</id>
            <properties>
                <activeProfile>test</activeProfile>
            </properties>
        </profile>
        <!--生产环境 -->
        <profile>
            <id>prod</id>
            <properties>
                <activeProfile>prod</activeProfile>
            </properties>
        </profile>
    </profiles>
    <!--本地使用maven install命令打包时需要注释掉end-->

注意:activeProfile 属性名称可以自定义,但是需要保证与下图中花括号中名称一致。


image.png

3.控制台使用maven打包命令打包。

例如:指定dev目录下的配置文件打包 mvn clean install -P dev

相关文章

  • Maven 多环境打包以及聚合打包(一)

    说明 本文只是一个总结参考文章:Maven 插件 - 打包时多环境配置文件设置 Maven 多环境打包 mav...

  • maven多环境打包配置

    1.在resources 目录中创建不同的项目启动配置文件。 resources目录结构如图: 2.修改项目pom...

  • maven多环境打包配置

    1.配置资源文件中的变量分隔符(标识符 ) 需要用以下配合,达到替换环境参数:dev或test、prod 能让ma...

  • Maven常用配置

    本文介绍了使用Maven作为构建工具的常用配置,包括指定jdk版本,jar包和依赖分开打包,多环境打包,配置私服,...

  • Maven插件-打包时多环境配置文件设置

    Maven插件-打包时多环境配置文件设置 引入公司SSO时,需要在web.xml文件中配置不同跳转URL,测试、生...

  • Maven 打包常用命令

    maven command 打包 打包跳过测试 打包指定环境 maven 打包 启动jar指定环境

  • 5.SpringBoot多环境配置

    maven多环境配置示例 SpringBoot多环境配置 Profile是Spring针对不同环境不同配置的支持。...

  • MAVEN 多环境打包

    这里的profile和Spring里面的profile是一样的道理,首先对默认的文件进行打包,然后读取默认激活的p...

  • Maven多环境打包

    场景 在应用部署的时候,往往遇到需要发布到不同环境的情况,而每个环境的数据库信息、密钥信息等可能会存在差异。举个例...

  • maven 多环境打包

    目录结构 在pom.xml中添加如下profile的配置: 当加入这些配置后就能在右侧看到目录如下:image.p...

网友评论

      本文标题:maven多环境打包配置

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