Maven多环境打包

 1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 2     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 3     <modelVersion>4.0.0</modelVersion>
 4     <groupId>com.ai</groupId>
 5     <artifactId>rgshcore</artifactId>
 6     <packaging>war</packaging>
 7     <version>1.0</version>
 8     <name>rgshcore</name>
 9     <properties>
10         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
11         <org.apache.spring.version>3.2.13.RELEASE</org.apache.spring.version>
12         <zookeeper.version>3.4.5</zookeeper.version>
13         <package.environment>quartz</package.environment>
14     </properties>
15
16
17     <profiles>
18         <profile>
19             <id>queue</id>
20             <properties>
21                 <!-- 此处package.environment 应该是自定义参数 -->
22                 <package.environment>queue</package.environment>
23             </properties>
24         </profile>
25         <profile>
26             <id>app</id>
27             <properties>
28                 <package.environment>app</package.environment>
29             </properties>
30             <!-- 默认生成环境 -->
31             <!--<activation> <activeByDefault>true</activeByDefault> </activation> -->
32         </profile>
33         <profile>
34             <id>test</id>
35             <properties>
36                 <!-- 此处release.file 应该是自定义参数 -->
37                 <release.file>test</release.file>
38             </properties>
39         </profile>
40         <profile>
41             <id>product</id>
42             <properties>
43                 <release.file>product</release.file>
44             </properties>
45         </profile>
46     </profiles>
47
48     <build>
49         <plugins>
50             <!-- 打包 -->
51             <plugin>
52                 <artifactId>maven-antrun-plugin</artifactId>
53                 <executions>
54                     <execution>
55                         <phase>compile</phase>
56                         <goals>
57                             <goal>run</goal>
58                         </goals>
59                         <configuration>
60                             <tasks>
61                                 <!-- 可以显示打包的环境 -->
62                                 <echo>@@@@@@@@@@@@@@@@@@${package.environment}@@@@@@@@@@@@@@@@@@@@@</echo>
63                                 <echo>@@@@@@@@@@@@@@@@@@${release.file}@@@@@@@@@@@@@@@@@@@@@</echo>
64                             </tasks>
65                         </configuration>
66                     </execution>
67                 </executions>
68             </plugin>
69             <!-- 打包 -->
70             <plugin>
71                 <groupId>org.apache.maven.plugins</groupId>
72                 <artifactId>maven-war-plugin</artifactId>
73                 <configuration>
74                     <archive>
75                         <addMavenDescriptor>false</addMavenDescriptor>
76                     </archive>
77                     <warName>rgshcore</warName>
78                     <!-- 过滤不打的文件 -->
79                     <packagingExcludes>WEB-INF/classes/spring/app/**,WEB-INF/classes/spring/queue/**,WEB-INF/classes/config/product/**,WEB-INF/classes/config/test/**</packagingExcludes>
80                     <webResources>
81                         <resource>
82                             <directory>src/main/resources/spring/${package.environment}/</directory>
83                             <targetPath>WEB-INF/classes/spring</targetPath>
84                             <filtering>true</filtering>
85                         </resource>
86                         <resource>
87                             <directory>src/main/resources/config/${release.file}/</directory>
88                             <targetPath>WEB-INF/classes/config</targetPath>
89                             <filtering>true</filtering>
90                         </resource>
91                     </webResources>
92                 </configuration>
93             </plugin>
94         </plugins>
95     </build>
96 </project>
时间: 2024-08-27 22:26:40

Maven多环境打包的相关文章

maven多环境打包配置

一.需求场景 1.开发环境和生产环境数据库地址和信息不同. 2.开发和生产日志等级不同 ... 二.最简单的实现方式 在 pom.xml 中配置 <!-- 设置不同环境打包 --> <profiles> <profile> <id>dev</id> <properties> <db.url>aa1</db.url> <db.username>bb1</db.username> <d

maven 分环境打包

一,创建分环境属性配置文件 src/build-config/build-develop.propertiessrc/build-config/build-product.propertiessrc/build-config/build-test.properties 例: build-develop.properties #数据库配置build.jdbc.url = jdbc:oracle:thin:@ip:port:databasebuild.jdbc.username = namebuil

maven 多环境打包

1.在项目的pom中添加 <build>     <resources>         <!-- Resource Filter -->         <resource>             <directory>src/main/resources</directory>             <filtering>true</filtering>         </resource>

Maven 多环境 打包

1.pom.xml文件添加profiles属性 <profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> <property> <name>env</name> <value>dev</value> </property> </ac

Maven插件之portable-config-maven-plugin(不同环境打包)

大型项目中,分开发环境.测试环境.生产环境等; 不同环境,配置不同,或数据源,或服务器,或数据库等; 问题来了,如何使用Maven针对不同的环境来打包呢? Maven提供了Profile的概念,用来解决此类问题,其原理很简单,就是使用变量替换;举个例子来说明,测试项目目录结构如下图所示: 比如开发环境和生产环境的数据库不同,db.properties配置文件内容如下: [html] view plain copy #测试库 db.url=192.10.2.168 db.username=dbte

Maven 结合 Spring profile对不同的部署环境打包部署

这是一个草鸡鸡冻人心的时刻,搞了2天终于搞定了,麻麻再也不用担心我部署出错了!!!!!!! 所有profile,spring和maven的,定义均要一致,否则,自己运行看看. 首先,先来讲下spring的profile功能,这个是方便项目的各种环境分离(开发.测试.生产),简单介绍下如何使用. 在beans中定义环境代码,项目中,我在beans.xml里定义 1 <beans profile="develop,test,product"></beans> 在数据

Eclipse搭建maven开发环境

上一篇学习了maven开发环境的搭建,并且手动编写了一个maven工程,但是这样子效率很低下,今天带大家学习在eclipse下搭建maven开发环境. 常用的maven命令 mvn clean :运行清理操作,会将target文件夹中的数据删除 mvn clean compile:先运行清理操作,之后运行编译操作,会将代码编译到target文件夹中. mvn clean test: 运行清理和测试 mvn clean package : 运行清理和打包 mvn clean install : 运

Webx autoconfig 多环境打包 使用总结

背景 最近在使用webx 的 autonconfig工具进行多环境间配置文件的变量替换. 常常我们遇到不同环境打包问题都是自己搞一套脚步来做,但是如何成体系的解决这一问题? autoconfig工具主要有两个用法: 不同环境环境的打包要使用不同的配置(如DB连接,版本信息等),这时候可以把需要替换的配置定义为占位符,使用maven的profile和maven的autoconfig插件来指定不同的properties文件,打包的时候,autoconfig就回去对应的properties文件中取对应

Maven的环境搭建及新建web项目

一.下载maven及环境变量的配置 下载地址 http://maven.apache.org/download.cgi 配置其环境变量  MAVEN_HOME=D:\apache-maven-3.0.5 即maven的解压缩路径 Path在其后追加%MAVEN_HOME%\bin (注意:两个目录间要用“;”隔开) 打开cmd 输入mvn -v 出现如下图所示则成功 二.Eclipse中的配置 打开windows->preferences->Maven 如图所示添加你的maven解压缩路径(注