Maven打包,把配置文件引用,打到外部
来源:互联网 发布:逆战磁暴矩阵 编辑:程序博客网 时间:2024/05/16 17:40
在SIT 环境测试的时候,因为服务器环境和本地环境可能不同,会造成不少问题,所以会进行多次打包。而且配置文件不同,所以每次打包都要修改配置文件,十分麻烦。
maven打包可以把配置文件引用打成外部的,这样就可以把sit环境的配置丢到服务器,然后每次打包动态选择配置文件引用地址,就很爽了。
1.maven,pom的配置,例如:
<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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <artifactId>666</artifactId> <groupId>com.xxx</groupId> <version>0.1.0</version> </parent> <artifactId>xxx</artifactId> <packaging>war</packaging> <name>xxx</name> <description>xxxxxx</description> <build> <finalName>xxx</finalName> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>true</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**</include> </includes> <filtering>true</filtering> </resource> </resources> </build> <dependencies> <dependency> <groupId>ojdbc</groupId> <artifactId>ojdbc</artifactId> <version>12.1.0.1-atlassian-hosted</version> </dependency> </dependencies> <properties> <file.config.path-sit>这里是sit配置路径,例如:/project-sit/config/xxx/</file.config.path-sit> <file.config.path-prod>这里是生产配置路径,例如:/project-prod/config/xxx/</file.config.path-prod> </properties> <profiles> <!-- 开发环境 --> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <some.config.path> classpath:config/some.properties <jdbc.config.path> classpath:config/jdbc.properties </jdbc.config.path> </properties> </profile> <!-- Sit测试环境 --> <profile> <id>sit</id> <properties> <some.config.path> file:${file.config.path-sit}some.properties </some.config.path> <jdbc.config.path> file:${file.config.path-sit}jdbc.properties </jdbc.config.path> </properties> </profile> <!-- 生成环境 --> <profile> <id>prod</id> <properties> <some.config.path> file:${file.config.path-prod}some.properties </some.config.path> <jdbc.config.path> file:${file.config.path-prod}jdbc.properties </jdbc.config.path> </properties> </profile> </profiles></project>
2.引用配置文件的xml的配置,例如:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"> <!-- 引入属性配置文件 --> <bean class="com.xxx.xxx.xxx.xxx"> <property name="locations"> <list> <value>${some.config.path}</value> <value>${jdbc.config.path}</value> </list> </property> </bean></beans>
3.在打包的时候。用maven进行install,命令如下:
mvn package -P sit
这里的sit就是sit环境的配置路径(如果在eclipse里打包,则去掉mvn这个命令头 ),如果使用这个打包命令,则打出来的war包里xml引用配置文件路径改变,如下:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 引入属性配置文件 --> <bean class="com.xxx.xxx.xxx.xxx"> <property name="locations"> <list> <value> file:/project-sit/config/xxx/some.properties </value> <value> file:/project-sit/config/xxx/jdbc.properties </value> </list> </property> </bean></beans>
4.这样就可以把打好的war包,直接丢到服务器上,然后把sit的配置文件也丢到配置的文件夹下,这样每次都不用修改配置文件,直接打包,重新部署就ok。copy代码要注意。这里是例子,删减了很多东西。希望不要误导同道们,相互学习。
—————-自动化的路还有很长,假如全自动需要100步,那这里只能算是第一步。路漫漫其修远兮,吾将上下而不停的,撸、抄袭、copy。
阅读全文
0 0
- Maven打包,把配置文件引用,打到外部
- 【maven】如何把配置文件打包到jar中
- Maven打包Spring boot,把依赖和配置文件及前端代码提取到jar文件外
- Maven打包Spring boot,把依赖和配置文件及前端代码提取到jar文件外
- Springboot引用外部配置文件
- Springboot引用外部配置文件
- Maven-打外部jar包
- Maven项目中将配置文件打包到jar包中
- maven 把classpath打包到manifes.mf文件中
- 使用 maven 打包配置文件
- maven不同配置文件打包
- Maven打包配置文件
- maven 配置文件打jar 包
- Spring Boot 将第三方依赖和配置文件打包在jar外部并引用
- maven 打包 引入外部jar
- maven 将依赖的外部jar包 统一打到指定目录文件夹中取
- maven项目引用外部jar
- maven 打包的时候,不把class打包到war包的情况
- 聚簇索引与非聚簇索引的区别
- 第十周 项目4
- 使用STS工具创建Spring Boot或Spring MVC项目
- robotFramework之ExcelLibrary库
- 深度剖析:最新云端开发工具如何实现敏捷+DevOps开发落地
- Maven打包,把配置文件引用,打到外部
- 【头条】华为提“智慧城市神经系统”概念,背后有何新意?
- 解析僵尸进程与孤儿进程
- 负载均衡层次概念
- app的维护成本怎么算?
- 业余小项目——tzxblog博客系统
- 全志android编译过程
- Q群操作CPA自动赚钱、引流的秘诀与技巧
- TIM Ctrl + Shift + A 截图时 TIM的窗口被隐藏后才能开始截图