使用maven profile实现多环境配置相关打包
2017-05-19 23:41
281 查看
项目开发需要有多个环境,一般为开发,测试,预发,正式4个环境,通过maven可以实现按不同环境进行打包部署,命令为:
mvn package -P dev
在eclipse中可以右击选项run configuration,输入上述命令。
PS:eclipse maven install和maven packege的区别在于前者除了打包到target外,还会install到本地仓库,这样其他引用的工程就可直接使用。
其中“dev“为环境的变量id, 可以自己定义, 我定义的名称为:dev,qa,pre,prod , 具体在pom.xml中的配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<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">
......
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>qa</id>
<properties>
<env>qa</env>
</properties>
</profile>
<profile>
<id>pre</id>
<properties>
<env>pre</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
......
<build>
<filters>
<filter>config/${env}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
......
</build>
</project>
1.profiles定义了各个环境的变量id
2.filters中定义了变量配置文件的地址,其中地址中的环境变量就是上面profile中定义的值
3.resources中是定义哪些目录下的文件会被配置文件中定义的变量替换,一般我们会把项目的配置文件放在src/main/resources下,像db,bean等,里面用到的变量在打包时就会根据filter中的变量配置替换成固定值
mvn package -P dev
在eclipse中可以右击选项run configuration,输入上述命令。
PS:eclipse maven install和maven packege的区别在于前者除了打包到target外,还会install到本地仓库,这样其他引用的工程就可直接使用。
其中“dev“为环境的变量id, 可以自己定义, 我定义的名称为:dev,qa,pre,prod , 具体在pom.xml中的配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<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">
......
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>qa</id>
<properties>
<env>qa</env>
</properties>
</profile>
<profile>
<id>pre</id>
<properties>
<env>pre</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
......
<build>
<filters>
<filter>config/${env}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
......
</build>
</project>
1.profiles定义了各个环境的变量id
2.filters中定义了变量配置文件的地址,其中地址中的环境变量就是上面profile中定义的值
3.resources中是定义哪些目录下的文件会被配置文件中定义的变量替换,一般我们会把项目的配置文件放在src/main/resources下,像db,bean等,里面用到的变量在打包时就会根据filter中的变量配置替换成固定值
相关文章推荐
- 使用maven profile实现多环境配置
- 使用maven profile 实现不同环境打包
- 使用maven profile指定配置文件打包适用多环境
- Maven profile结合Maven AntRun Plugin实现不同环境配置文件分离打包
- 使用maven profile指定配置文件打包适用多环境
- 使用maven profile指定配置文件打包适用多环境的方法
- Maven使用profile 和 filtering实现多种环境下配置打包
- 使用SVN+CruiseControl+ANT实现持续集成之二----环境搭建和配置介绍
- 使用maven profile实现多环境可移植构建
- 使用Ant实现多渠道,多环境打包apk
- 使用maven profile实现多环境可移植构建
- maven profile实现多环境构建 (单项目多套配置)
- 配置cocos2dx安卓开发打包环境——使用Cygwin编译,ant打包
- 使用maven profile实现多环境可移植构建
- as通过gradle实现多渠道打包+使用配置文件进行版本管理+指定apk输出路径和apk文件名
- 使用maven profile实现多环境可移植构建
- iDempiere 使用指南 windows下eclipse开发环境配置及打包下载
- 使用vim配置开发环境时容易出错的相关记录
- ubuntn 12.04 rk环境及 相关使用 配置
- maven 使用maven profile实现多环境可移植构建