Maven插件实现的autoconfig机制(转)
2015-01-28 18:01
218 查看
autoconfig这种机制在软件开发和发布的过程中是非常方便也是非常必要的一种动态替换配置信息的一种手段,一种很贴切的比喻:这个就像在windows下面安装一个软件时,我们按照安装向导给我们弹出提示填写信息一样(这些信息就是一些定制化的信息)。
Maven的强大插件机制,可以和autoconfig机制结合起来,发挥巨大的威力。
实际项目中,基本都是在deploy下面实现配置文件的读取和替换的。这里,其实就是利用了一个maven-autoconf-plugin插件实现的这个功能。具体deploy下面pom.xml的配置片段如下:
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
Maven的强大插件机制,可以和autoconfig机制结合起来,发挥巨大的威力。
实际项目中,基本都是在deploy下面实现配置文件的读取和替换的。这里,其实就是利用了一个maven-autoconf-plugin插件实现的这个功能。具体deploy下面pom.xml的配置片段如下:
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
相关文章推荐
- SpringBoot使用 maven autoConfig插件打jar包(一)
- 【maven】mvn-autoconfig插件-配置不同开发环境
- maven 插件之 AutoConfig 工具使用笔记
- PHP中插件机制的一种实现方案
- 灵活正确的实现.NET插件机制开发者在线 Builder.com.cn 更新时间:2008-08-05作者: 来源:开发者在线
- system-config-date的实现机制
- 用 .NET 实现插件机制
- 用 .NET 实现插件机制
- PHP中插件机制的一种实现方案
- NET的插件机制的简单实现
- (转)用 .NET 实现插件机制
- BlogWriter博客客户端-3 及 插件机制实现原理
- 用 .NET 实现插件机制
- php实现网站插件机制的方法
- php实现网站插件机制的方法
- 灵活正确的实现.NET插件机制
- 用 .NET 实现插件机制
- 如何用实现.NET的插件机制
- 灵活正确的实现.NET插件机制
- BlogWriter博客客户端-3 及 插件机制实现原理