`
dingjob
  • 浏览: 181080 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

maven 插件开发总结

阅读更多

学习了Maven的插件开发后,看了下我们项目的maven管理。得出一些结论:

 一. 一点基础

1. 当你省略了 插件的 packageId和version等,maven就会多执行一些查找的操作,所以命令不是越精简越好。精简意味着你节省的时间,maven都会将它花在查找和遍历上。

 

2.-DgroupId=com.job.maven.plugins -DartifactId=greeting-maven-plugin

 

DgroupId 为 项目的目录,也是发布到本地后的maven库路径  DartifactId 为项目名称。

 

二.选择一个插件解析项目结构

1. 如何将你的default配置写入到antx.perpties?

 

项目中配置了如下插件,主要作用是在build的时候将task.schedule.clearLogData2这种参数等set为相应值,下

面详细介绍这种插件的作用和对应pom文件解析。

 

<groupId>com.job.maven.plugins</groupId>
	<artifactId>maven-autoconf-plugin</artifactId>
	<version>0.2</version>
<executions>
	<execution>
		<phase>process-resources</phase>
			<goals>
			<goal>config</goal>
			</goals>
	</execution>
</executions>

 

 

对应packaging项的配置,一般总体的parent配置文件如下:

<name>aa.project</name>
 <groupId>com.job.parent</groupId>
 <version>1.2.0</version>
 <artifactId>parent.project</artifactId>
 <packaging>pom</packaging>

 

而对应的子项目下则定义为 jar包或者war包,如下:

 

 <groupId>com.job.child1</groupId>
  <artifactId>child1.webapp</artifactId>
  <packaging>war</packaging>

packaging有四种取值:pom,war,jar等,对于总控的pom 它是用来继承的,不需要将${变量}的这种形式进行一个配置,而对于子项目是需要的,我们来看其插件源码。

 

 原理是:如果找到总控的pom,则直接跳过,如果是war包或者jar包等子项目的,则将其default值写入config.perperties,并写到child1.properties。

 

 

2.  如何将生成的config.perperties读出来,什么时候读出来?

 

写到config.properties里面的变量,会在容器启动阶段将其缓存起来,我们build后的需要变量的xml文件并没有直接存值.打开一个jar包的xml配置可以看到

 <bean id="esbPriceService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
  <property name="serviceUrl" value="${hessian.url.esbPriceService}" /> 
  <property name="serviceInterface" value="org.esb.biz.product.EsbPriceService" /> 
- <property name="proxyFactory">
  <ref bean="hessianProxyFactory" /> 
  </property>
 </bean>

 所以这个是动态加载的过程,靠的是Spring配置的 PropertyResourceConfigurer,

 

<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="properties">
			<ref bean="envProperties"></ref>
		</property> 
	</bean>
	
	<bean id="envProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
		<property name="locations">
			<list>
				<value>classpath*:risk.properties</value>
			</list>
		</property>		
		<property name="fileEncoding">
			<value>GB2312</value>
		</property>
	</bean>
	

 

 这里我想到,如果这样的话,发布的时候配置文件更新,是可以直接通过更新config.properties,并刷新下内存来实现,这里恐怕就要借鉴规则引擎后台刷新内存的方式了。(本来是静态的,改成动态的还是有问题的,比如,如何在改变时禁止外部访问,可以设计为动态的,类似jboss的开发模式或者jtools)

 

分享到:
评论
1 楼 wzju64676266 2010-07-14  
你是阿里巴巴的同事吗

相关推荐

Global site tag (gtag.js) - Google Analytics