Maven插件实现的autoconfig机制(转)
2024-10-13 05:41:42
autoconfig这种机制在软件开发和发布的过程中是非常方便也是非常必要的一种动态替换配置信息的一种手段,一种很贴切的比喻:这个就像在windows下面安装一个软件时,我们按照安装向导给我们弹出提示填写信息一样(这些信息就是一些定制化的信息)。
Maven的强大插件机制,可以和autoconfig机制结合起来,发挥巨大的威力。
实际项目中,基本都是在deploy下面实现配置文件的读取和替换的。这里,其实就是利用了一个maven-autoconf-plugin插件实现的这个功能。具体deploy下面pom.xml的配置片段如下:
- <profiles>
- <!-- Dev profile will configure all files and copy them to target/dev, for testing purpose -->
- <profile>
- <id>dev</id>
- <activation>
- <property>
- <name>env</name>
- <value>!release</value>
- </property>
- </activation>
- <build>
- <plugins>
- <!-- do auto config for integration test -->
- <plugin>
- <groupId>com.alibaba.maven.plugins</groupId>
- <artifactId>maven-autoconf-plugin</artifactId>
- <version>0.3-alpha-9</version>
- <executions>
- <execution>
- <phase>pre-integration-test</phase>
- <goals>
- <goal>config</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <destFiles>
- <destFile>${project.basedir}</destFile>
- </destFiles>
- <includeDescriptorPatterns>
- <!-- intl-site flavor -->
- <includeDescriptorPattern>autoconf/auto-config.xml</includeDescriptorPattern>
- <!-- china-site flavor -->
- <includeDescriptorPattern>conf/META-INF/autoconf/auto-config.xml</includeDescriptorPattern>
- </includeDescriptorPatterns>
- <includePackagePatterns>
- <includePackagePattern>**/*.war</includePackagePattern>
- </includePackagePatterns>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
这里,又一次应用了COC的思想,插件会去扫描autoconf/auto-config.xml或者conf/META-INF/autoconf/auto-config.xml。
目前这个插件还比较鸡肋,不过基本功能都是有的,详细的介绍,可以直接参考他的官方介绍:http://repo.alibaba-inc.com/mvn/internal/snapshots/sites/maven-autoconf-plugin/config-mojo.html
常用的几个属性列举如下:
- includeDescriptorPatterns:autoconfig所要扫描的描述文件的匹配路径。
- userProp:指定用户实际使用配置信息的配置文件的路径,如:-DuserProp=/home/abc/properties.txt
本文来自于:http://hittyt.iteye.com/blog/889158
最新文章
- CoreProfiler/NanoProfiler性能调试监控系列总目录
- 机器学习之KNN算法思想及其实现
- 【poj2741】 Colored Cubes
- 从出租车司机到大BOSS的转型之路
- 夺命雷公狗ThinkPHP项目之----企业网站16之文章批量删除的完成
- plupload上传控件错误exec(this.uid, component, action, args)
- 【转】android应用程序签名
- javascript显示倒计时控制按钮
- 如何定时备份远程mysql数据库
- poj 3608 旋转卡壳求不相交凸包最近距离;
- c 查找A字符串在B字符串中是否存在,计算出现的次数
- .Net 文本框实现内容提示(仿Google、Baidu)
- AR9331中Linux内核启动中与IRQ中断相关的文件
- 机器学习 —— 基础整理(六)线性判别函数:感知器、松弛算法、Ho-Kashyap算法
- form表单中enctype属性作用
- org.json.JSONObject的optXXX方法
- ajaj简介
- Delphi下MSMQ(Mircosoft Message Queue)实例(私有队列)
- k8s1.13.3安装istio(helm方式)
- ECharts中color : function的用法(转)