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包里头。 

  • 相关阅读:
    OpenStack安装及监控配置视频教程
    具有可视化的功能的一款开源软件Gource
    Ubuntu 12.04使用演示
    VisualRoute for Mac OS 体验
    P1006-传纸条
    Leetcode-1157 Online Majority Element In Subarray(子数组中占绝大多数的元素)
    Leetcode-1156 Swap For Maximum Repeated Substring(单字符重复子串的最大长度)
    Leetcode-1155 Number of Dice Rolls With Target Sum(掷骰子的N种方法)
    Leetcode-1154 Ordinal Number Of Date(一年中的第几天)
    P1508-Likecloud-吃、吃、吃
  • 原文地址:https://www.cnblogs.com/shawWey/p/12214286.html
Copyright © 2011-2022 走看看