zoukankan      html  css  js  c++  java
  • Maven通过profiles多环境配置打包

    本文主要介绍,在项目开发过程中,开发环境、测试环境、生产环境在配置的过程中,如何通过maven自动打包加入到war中。

    一、新建一个testprofile的maven项目。

    在resources文件里头新增dev、online、test文件夹,并把相关的jdbc配置放到具体目录下。

    二、pom配置文件编写

    pom.xml相关配置如下,主要注意下profiles那块的配置。

    <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.fjnx.cn</groupId>
      <artifactId>testprofile</artifactId>
      <version>1.0.0</version>
      <packaging>war</packaging>
      <dependencies>
          <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
          </dependency>
      </dependencies>
      <profiles>
            <profile>  
                <!-- 开发环境 -->  
                <id>dev</id>  
                <properties>  
                    <env>dev</env>
                </properties>  
                <activation>  
                    <!-- 默认激活该profile节点-->
                    <activeByDefault>true</activeByDefault>  
                </activation> 
                <build>
                    <resources>
                        <resource>
                            <directory>src/main/resources/dev</directory>
                        </resource>
                        <resource>
                            <directory>src/main/resources</directory>
                        </resource>
                    </resources>
                </build>
            </profile>  
            <profile>  
                <!-- 测试环境 -->  
                <id>test</id>  
                <properties>  
                    <env>qa</env>
                </properties>
                <build>
                    <resources>
                        <resource>
                            <directory>src/main/resources/test</directory>
                        </resource>
                        <resource>
                            <directory>src/main/resources</directory>
                        </resource>
                    </resources>
                </build>
            </profile>    
            <profile>
                <!-- 生产环境 -->
                <id>online</id>  
                <properties>
                    <env>online</env>
                </properties>  
                <build>
                    <resources>
                        <resource>
                            <directory>src/main/resources/online</directory>
                        </resource>
                        <resource>
                            <directory>src/main/resources</directory>
                        </resource>
                    </resources>
                </build>
            </profile> 
      </profiles>
    </project>

    三、选择具体的profile进行打包

    方式一:点击项目,右键properties,选择maven,选择打包的环境:

     

    方式二:点击项目,右键maven,点击select maven profiles选择具体的环境:

      

     

    然后点击保存即可。

    最后就可以运行环境,直接打包或者导出war即可,这样,你选择的配置文件,就会出现在相应的war包里头。 

  • 相关阅读:
    mysql 查询某年某月数据~(如果数据表用时间戳)
    mongo_4.25 find() hasNext() next()
    在YII框架中有2中方法创建对象:
    bootsrap[$data]
    date
    cookie
    JavaScript shell, 可以用到 JS 的特性, forEach
    在 Yii框架中使用session 的笔记:
    mysql查询今天、昨天、7天、近30天、本月、上一月 数据
    Python 自定义异常练习
  • 原文地址:https://www.cnblogs.com/shawWey/p/12214286.html
Copyright © 2011-2022 走看看