MAVEN开发,测试环境Properties的替换支持
2015-08-30 00:00
281 查看
摘要: 对开发环境,生产环境,测试等环境的支持
参考
http://blog.csdn.net/stark_summer/article/details/42743007
1)在src/main/resources下面建立dev,product目录
src/main/resources/dev
src/main/resources/product
2)分别在这两个路径下放置适合各自环境的配置文件,如db.properties, log4j.properties等
3)配置pom,进行环境的选择。
3.1)配制plugin
3.2) 配置的Profiles
3.3) 执行mvn clean package -Pdev 完成对dev环境的应用生成。
注:其实可以在java/main/resources目录下直接放开发环境的配置,这样在开发时就不需要做任何修正。只有要发布其他环境的时候,才执行maven命令进行包的生成。
jar文件的替换策略
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<tasks>
<echo message="********************** copy resources to classpath*************************"/>
<echo message="********************** copy ${resources.dir} to classpath*************************"/>
<copy todir="target/classes" overwrite="true">
<fileset dir="${resources.dir}">
<include name="*.*"/>
<include name="*/*.*"/>
</fileset>
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
参考
http://blog.csdn.net/stark_summer/article/details/42743007
1)在src/main/resources下面建立dev,product目录
src/main/resources/dev
src/main/resources/product
2)分别在这两个路径下放置适合各自环境的配置文件,如db.properties, log4j.properties等
3)配置pom,进行环境的选择。
3.1)配制plugin
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <archive> <addMavenDescriptor>false</addMavenDescriptor> </archive> <webResources> <resource> <!-- this is relative to the pom.xml directory --> <directory>src/main/resources/${package.environment}</directory> <targetPath>WEB-INF/classes</targetPath> <filtering>true</filtering> </resource> </webResources> <packagingExcludes> WEB-INF/classes/dev/, WEB-INF/classes/product/ </packagingExcludes> </configuration> </plugin> |
<profiles> <profile> <id>product</id> <properties> <package.environment>product</package.environment> </properties> </profile> <profile> <id>dev</id> <properties> <package.environment>dev</package.environment> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> </profiles> <properties> <package.environment>dev</package.environment> </properties> |
注:其实可以在java/main/resources目录下直接放开发环境的配置,这样在开发时就不需要做任何修正。只有要发布其他环境的时候,才执行maven命令进行包的生成。
jar文件的替换策略
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<tasks>
<echo message="********************** copy resources to classpath*************************"/>
<echo message="********************** copy ${resources.dir} to classpath*************************"/>
<copy todir="target/classes" overwrite="true">
<fileset dir="${resources.dir}">
<include name="*.*"/>
<include name="*/*.*"/>
</fileset>
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
相关文章推荐
- 网站结构seo优化技巧汇总--Dede织梦cms
- getopt笔记
- Note For Linux By Jes(18)-X Window 配置介绍
- linux的vsftpd配置教程-本人亲测
- Note For Linux By Jes(17)-软件安装: RPM, SRPM 与 YUM 功能
- WAMP环境配置
- Opencv计算数组加权和
- Opencv计时函数
- 0823第三课-2 Linux的文件系统 bash基础特性
- Opencv感兴趣区域-ROI
- Opencv多通道图像混合-滚动条
- Linux 的yum详解
- Opencv多通道图像混合
- linux shell (二)正则表达式
- Linux How to add a new disk to LVM
- linux运维实战练习-2015年8月27日课程作业
- linux运维实战练习-2015年8月27日课程作业
- Android的系统架构
- 读书笔记之linux/unix系统编程手册(31)
- 【OpenCV入门教程之十七】OpenCV重映射 & SURF特征点检测合辑