maven profile实现多环境打包
来源:互联网 发布:现货倚天技术指标源码 编辑:程序博客网 时间:2024/05/01 17:59
项目开发需要有多个环境,一般为开发,测试,预发,正式4个环境,通过maven可以实现按不同环境进行打包部署,加载不同环境下的配置文件内容。maven打包命令为:mvn clean -U package -Pdev -Dmaven.test.skip=true。
其中“dev“为环境的变量id, 可以自己定义, 我定义的名称为dev、test、prod。具体在pom.xml中的定义如下:
<build><resources><resource><directory>src/main/resources</directory><filtering>true</filtering></resource></resources><pluginManagement><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-clean-plugin</artifactId><version>${maven-clean-plugin.version}</version><configuration><filesets><fileset><directory>src/main/webapp/WEB-INF/lib</directory><includes><include>**/*.jar</include></includes><followSymlinks>false</followSymlinks></fileset></filesets></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><version>${maven-dependency-plugin.version}</version><executions><execution><id>copy</id><phase>package</phase><goals><goal>copy-dependencies</goal></goals><configuration><outputDirectory>src/main/webapp/WEB-INF/lib</outputDirectory></configuration></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>${maven-war-plugin.version}</version><configuration><failOnMissingWebXml>false</failOnMissingWebXml><webResources><resource><directory>src/main/webapp</directory><filtering>true</filtering></resource></webResources></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.2</version><configuration><source>1.6</source><target>1.6</target></configuration></plugin></plugins></pluginManagement></build><profiles><profile><!-- 本地开发环境 --><id>dev</id><properties><env>dev</env></properties><activation><activeByDefault>true</activeByDefault></activation></profile><profile><!-- 测试环境 --><id>test</id><properties><env>test</env></properties></profile><profile><!-- 生产环境 --><id>prod</id><properties><env>prod</env></properties></profile></profiles>
配置文件的定义如下:
然后在spring的配置文件中根据环境的不同动态加载配置文件:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath:com/flysun/server/config/${env}/*.properties</value></list></property></bean>
如果在eclipse中的话,可以直接如下:
1.profiles定义了各个环境的变量id
2.resources中是定义哪些目录下的文件会被配置文件中定义的变量替换,一般我们会把项目的配置文件放在src/main/resources下,像db,bean等,里面用到的变量在打包时就会根据filter中的变量配置替换成固定值
也可参考博客地址:http://www.cnblogs.com/yjmyzz/p/3941043.html
阅读全文
0 0
- maven profile实现多环境打包
- maven profile实现多环境打包
- Maven Profile多环境打包
- java学习笔记8 - maven profile实现多环境打包
- java学习笔记8 - maven profile实现多环境打包
- 使用maven profile 实现不同环境打包
- maven通过profile不同,实现环境进行打包
- Maven profile实现多环境配置
- 使用maven profile实现多环境配置
- 使用maven profile指定配置文件打包适用多环境
- Maven profile结合Maven AntRun Plugin实现不同环境配置文件分离打包
- maven 使用maven profile实现多环境可移植构建
- 使用maven profile实现多环境可移植构建
- 使用maven profile实现多环境可移植构建
- 使用maven profile实现多环境可移植构建
- 使用maven profile实现多环境可移植构建
- Maven 整合 spring profile实现多环境自动切换
- 使用maven profile实现多环境可移植构建
- WIN
- Description Resource Path Location Type Access restriction: The constructor BASE64Decoder() is not a
- JAVA工具类,Local解析
- 文章标题
- jQuery实现的截取字符串后面以省略号替代
- maven profile实现多环境打包
- mybatis延迟加载开关
- 作业2017.10.12
- 模板:块状链表
- springMVC中多个自定义拦截器方法的执行顺序
- elasticsearch+kibana安装
- Hive学习--架构和基本组成
- Linux下安装mysql
- 熵编码之CABAC