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

  • 相关阅读:
    SQL Server 2005 中的分区表和索引 [轉]
    [导入]使用RDLC报表(一)
    正则表达式30分钟入门教程[轉]
    C#的TextBox控件输入测试只允许输入数字的测试:
    c#创建access数据库和数据表[转]
    [导入]使用RDLC报表(二)使用自定义数据集
    ASP.net 文件下載
    [导入]使用RDLC报表(四)钻取式报表
    [导入]使用RDLC报表(三)向RDLC报表传入参数
    C# SQL server2000中保存的图像
  • 原文地址:https://www.cnblogs.com/shawWey/p/12214286.html
Copyright © 2011-2022 走看看