Maven根据不同个环境打包, 获取不同的配置文件等等
http://www.cnblogs.com/tartis/p/5391079.html
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.</modelVersion>
<groupId>book</groupId>
<artifactId>book</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>book</name> <repositories>
<repository>
<id>eap</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories> <pluginRepositories>
<pluginRepository>
<id>eap</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories> <properties>
<project.build.sourceEncoding>UTF-</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target> <package.environment>local</package.environment>
</properties> <dependencies> <dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.2--jdbc4</version>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.2..RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.2..RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2..RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2..RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2..RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>3.2..RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.2..RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.2..RELEASE</version>
</dependency> <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency> <dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency> <dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.</version>
</dependency> </dependencies> <profiles>
<profile>
<id>local</id>
<properties>
<package.environment>local</package.environment>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>product</id>
<properties>
<package.environment>product</package.environment>
</properties>
</profile>
</profiles> <build>
<finalName>book</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>local/*</exclude>
<exclude>product/*</exclude>
<exclude>public/*</exclude>
</excludes>
</resource>
</resources> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
<warName>book</warName>
<webResources>
<resource>
<directory>src/main/resources/${package.environment}</directory>
<targetPath>WEB-INF/classes</targetPath>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/public</directory>
<targetPath>WEB-INF/classes</targetPath>
<filtering>true</filtering>
</resource>
<!--<resource>-->
<!--<directory>${project.build.directory}/classes</directory>-->
<!--<includes>-->
<!--<include>**/*.properties</include>-->
<!--<include>**/*.xml</include>-->
<!--</includes>-->
<!--</resource>-->
</webResources>
</configuration>
</plugin>
</plugins>
</build> </project>
关键代码:
<profiles>
<profile>
<id>local</id>
<properties>
<package.environment>local</package.environment>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>product</id>
<properties>
<package.environment>product</package.environment>
</properties>
</profile>
</profiles>
这里就是不同的resources文件夹, 我这里只区分本地 产品; 设置为true的就是默认被激活的. 所以后面打包默认就是本地;
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>local/*</exclude>
<exclude>product/*</exclude>
<exclude>public/*</exclude>
</excludes>
</resource>
</resources>
这里就是我的资源文件, public里面存放我的公用的, 比如Spring的配置文件, 就是本地与产品都一样的;local 与 product一看就知道了;
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
<warName>book</warName>
<webResources>
<resource>
<directory>src/main/resources/${package.environment}</directory>
<targetPath>WEB-INF/classes</targetPath>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/public</directory>
<targetPath>WEB-INF/classes</targetPath>
<filtering>true</filtering>
</resource>
<!--<resource>-->
<!--<directory>${project.build.directory}/classes</directory>-->
<!--<includes>-->
<!--<include>**/*.properties</include>-->
<!--<include>**/*.xml</include>-->
<!--</includes>-->
<!--</resource>-->
</webResources>
</configuration>
</plugin>
这里就是war的插件了,
${package.environment}
就是动态指定文件夹了.
<filtering>true</filtering>
这里一定需要设置为true才行.
然后就差不多了. 最后执行 mvn clean ; mvn compile; mvn package; 这里是Maven的生命周期, 其他介绍的文章太多了, 我就不再具体讲. 如果说我要打product的war包;
mvn clean ; mvn compile; mvn -Pproduct package;
那就激活了product 的资源文件;
就这样子, 很简单吧~
Maven根据不同个环境打包, 获取不同的配置文件等等的更多相关文章
- maven 使用-P指定环境打包,linux移动配置文件失败,windows成功!
问题描述: windows机器使用-P指定环境打包,最后组装文件组装成功,配置文件成功移动,linux下却只移动了jar包. windows: linux: ...
- Maven_根据不同个环境打包, 获取不同的配置文件等等
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- 用maven按环境打包SpringBoot的不同配置文件
利用maven按环境打包SpringBoot的不同配置文件 application-dev.properties对应开发环境 application-test.properties对应测试环境 app ...
- 【转】maven profile实现多环境打包
作为一名程序员,在开发的过程中,经常需要面对不同的运行环境(开发环境.测试环境.生产环境.内网环境.外网环境等等),在不同的环境中,相关的配置一般不一样,比如数据源配置.日志文件配置.以及一些软件运行 ...
- maven profile实现多环境打包
快速解决: 项目目录 1.pom文件中添加profile <profiles> <profile> <!-- 本地开发环境 --> <id>dev< ...
- Maven根据不同的环境打包不同的配置
前言: 在开发过程中,我们的软件会面对不同的运行环境,比如开发环境.测试环境.生产环境,而我们的软件在不同的环境中,有的配置可能会不一样,比如数据源配置.日志文件配置等等. 那么就需要借助maven提 ...
- maven为不同环境打包(hibernate)-超越昨天的自己系列(6)
超越昨天的自己系列(6) 使用ibatis开发中,耗在dao层的开发时间,调试时间,差错时间,以及适应修改需求的时间太长,导致项目看起来就添删改查,却特别费力. 在项目性能要求不高的情况下,开始寻 ...
- Maven插件之portable-config-maven-plugin(不同环境打包)
在大型的项目组中,分不同的开发环境,测试环境,生产环境(说白了就是配置文件不同,或者数据源,或者服务器,或者数据库等);问题来了,如何使用Maven针对不同的环境来打包呢? Maven提供了Profi ...
- Maven适配多种运行环境的打包方案
项目从开发到部署会历经多个运行环境,如开发环境.测试环境和生产环境,不同环境中项目的配置文件通常也会不同,典型的如数据库连接配置.我们当然不希望每次部署打包前都去修改配置文件以适配环境,利用Maven ...
随机推荐
- bridge
1 意图:将抽象部分与实现部分分离,使得它们都可以独立地变化 2 别名:Handle/Body 3 动机:客户在创建窗口时应该不涉及到具体实现部分.仅仅是窗口的实现部分依赖于应用运行的平台. 客户代码 ...
- iOS开发 Apple Pay
一.什么是Apple Pay? 1. 概念 Apple Pay,简单来说, 就是一种移动支付方式.通过Touch ID/ Passcode,用户可使用存储在iPhone 6, 6p等设备上的信用卡和借 ...
- 函数指针与指针函数以及typedef
c难于理解的是指针,其魅力之处也是指针,函数方法结构,化繁为简可以理解为:返回值 函数名(形参表),具体来说: 返回值:1.可以为空void 2.基本数据类型char short int long f ...
- 【转】Mysql中varchar存放中文与英文所占字节异同
本文转自Ruby china, 原文地址:https://ruby-china.org/topics/24920 一.关于UTF-8 UTF-8 Unicode Transformation Form ...
- 编程之美--2. Trie树 (Trie图)
#1014 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助, ...
- Android中SQLite下 Cursor的使用。
引自博客大神一篇文 地址: http://blog.sina.com.cn/s/blog_15e2abdd90102wcdu.html rawQuery()方法用于执行select语句. /* ...
- 通过j-interop访问WMI实例代码
代码: import java.net.UnknownHostException; import java.util.logging.Level; import org.jinterop.dcom.c ...
- javascript笔记7-事件
主要讲事件流.事件捕获.事件冒泡.事件处理程序.事件属性.事件类型.内存和优化等. 由于本文已经在微信订阅号上发布,为了防止原创性冲突检测,因此本文在此处已经删除. 详细请扫描订阅号二维码,查看历史信 ...
- css实现微信信息背景qq聊天气泡
用css实现一个椭圆形状的背景框很好实现 css: div{ width:200px; height:80px; background-color: #78DDF8; border-radius:10 ...
- NOSCRIPT标签的用处
NOSCRIPT标签用来定义在脚本未被执行时的替代内容.也可以用在检测浏览器是否支持脚本,若不支持脚本则可以显示NOSCRIPT标签里的innerText. eg:<body> ... . ...