zoukankan      html  css  js  c++  java
  • maven插件 按配置加载不同环境配置文件进行打包(maven-war-plugin)

    1.配置多种不同环境

    如(本地local,开发dev,测试test 环境等)

     1   <profiles>
     2         <profile>
     3             <id>local</id>
     4             <properties>
     5                 <package.environment>local</package.environment>
     6             </properties>
     7         </profile>
     8         
     9         <profile>
    10             <id>dev</id>
    11             <properties>
    12                 <package.environment>dev</package.environment>
    13             </properties>
    14             <!-- 指定使用哪一个配置 -->
    15             <activation>
    16                 <activeByDefault>true</activeByDefault>
    17             </activation>
    18         </profile>
    19 
    20         <profile>
    21             <id>test</id>
    22             <properties>
    23                 <package.environment>test</package.environment>
    24             </properties>
    25         </profile>
    26     </profiles>

    其中 第15-17行代码指定使用此环境配置,可以放在不同的<profile>下,需要在项目目录下创建对应配置的文件夹如local、dev、test等 如下

    common文件夹下为项目通用配置,dev下为开发环境的配置,test为测试环境下的

    2.在build下配置以下内容

     1 <build>
     2         <finalName>demo项目名称</finalName>
     3         <resources>
     4             <resource>  
     5                 <directory>src/main/java</directory>  
     6                 <includes>  
     7                     <include>**/*.xml</include>  
     8                 </includes>  
     9                 <filtering>false</filtering>  
    10             </resource>  
    11             <resource>
    12                 <directory>src/main/resources</directory>
    13                 <filtering>true</filtering>
    14                 <excludes>
    15                     <exclude>local/*</exclude>
    16                     <exclude>test/*</exclude>
    17                     <exclude>dev/*</exclude>
    18                     <exclude>common/*</exclude>
    19                 </excludes>
    20             </resource>
    21         </resources>
    22         <plugins>
    23             <plugin>
    24                 <groupId>org.apache.maven.plugins</groupId>
    25                 <artifactId>maven-war-plugin</artifactId>
    26                 <version>2.3</version>
    27                 <configuration>
    28                     <encoding>UTF-8</encoding>  
    29                     <archive>
    30                         <addMavenDescriptor>false</addMavenDescriptor>
    31                     </archive>
    32                     <warName>NACPortal_${package.environment}</warName>
    33                     <webResources>
    34                         <resource>
    35                             <directory>src/main/resources/${package.environment}</directory>
    36                             <targetPath>WEB-INF/classes</targetPath>
    37                             <filtering>true</filtering>
    38                         </resource>
    39                         <resource>
    40                             <directory>src/main/resources/common</directory>
    41                             <targetPath>WEB-INF/classes</targetPath>
    42                             <filtering>true</filtering>
    43                         </resource>
    44                     </webResources>
    45                 </configuration>
    46             </plugin>
    47             <!-- 编译配置 按照不同版本进行配置-->
    48             <plugin>
    49               <artifactId>maven-compiler-plugin</artifactId>
    50               <configuration>
    51                   <source>1.8</source>
    52                   <target>1.8</target>
    53                   <encoding>UTF-8</encoding>
    54                   <compilerArguments>
    55                    <extdirs>srcmainwebappWEB-INFlib</extdirs>
    56                   </compilerArguments>
    57               </configuration>
    58             </plugin>
    59         </plugins>
    60 </build>

    开发的过程中就可以通过配置

    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>

    在相应配置环境 进行不同环境下的打包。

    执行mvn install 后即可生成相应的war包 如 project_dev.war,project_test.war等

    至此,大功告成!!

    profile  ['prəʊfaɪl]  详细X
    基本翻译
    n. 侧面;轮廓;外形;剖面;简况
    vt. 描…的轮廓;扼要描述
    vi. 给出轮廓
    网络释义
    Profile: 轮廓
    Bevel Profile: 轮廓倒角
  • 相关阅读:
    Python基础笔记(五)
    Python基础笔记(四)
    Python基础笔记(三)
    Python基础笔记(二)
    Python基础笔记(一)
    分页存储过程
    MD Test
    vue路由的配置技巧
    Echarts的使用与配置项
    js中call,apply,bind之间的区别
  • 原文地址:https://www.cnblogs.com/zluckiy/p/10132304.html
Copyright © 2011-2022 走看看