码迷,mamicode.com
首页 > 系统相关 > 详细

ANT之macrodef

时间:2015-02-05 07:08:20      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:macrodef ant

macrodef 直接解释是宏, 理解上可以是自定义标签或者自定义函数

对于大型部署提高代码利用率

 

为了方便理解通过以下代码:

<macrodef name="macro-send-file">
  		<attribute name="host" />
		<attribute name="toPath" />
		<attribute name="file" />
		<attribute name="userID" />
		<attribute name="password" />
<sequential>
<echo>@{userID}:@{password}@@@{host}:@{toPath}</echo>
<scp verbose="false" trust="true" localFile="@{file}" todir="@{userID}:@{password}@@@{host}:@{toPath}" failonerror="true" />
<!-- sshexec trust="true" host="@{host}" username="@{userID}" password="@{password}" command="chmod -R u+rw,g+rwx @{toPath}/*.ear"/ --><sshexec trust="true" host="@{host}" username="@{userID}" password="@{password}" command="chown thangamm:wadmfsms  @{toPath}/*.ear"/>
<echo>Sent @{file} to @{host}:@{toPath}</echo>
			
<!-- delete build dir -->
<echo message="clean app project" />
<!-- after done, should clean the preparation folders but keep release folder -->		
<delete dir="${build.dir.app}${file.separator}${name.bin}" failonerror="false" />
<delete dir="${build.dir.app}${file.separator}${name.docs}" failonerror="false" />
<delete dir="${build.dir.app}${file.separator}${name.reports}" failonerror="false" />
<delete dir="${build.dir.app}${file.separator}${name.stage}" failonerror="false" />
		
			<echo message="clean core project" />
			<delete dir="${build.dir.core}" failonerror="false" />		
			
			<echo message="clean web project" />
			<delete dir="${build.dir.web}" failonerror="false" />				
		</sequential>		
	</macrodef>

 

<macrodef name="macro-send-file">  name 属性说明这个自定义宏的名字 通过这个name 来调用

如下调用这个宏

<macro-send-file file="${file}" host="${autodeploy.host}" topath="${autodeploy.path}/${envName}" userid="${autodeploy.userID}" password="${autodeploy.password}" />

<attribute name="host" /> 表示宏的输入参数(相当于函数的参数)。在marcodef 中不同通过${}来调用attrbute 的值而要通过@{}。例如显示传入参数userID 是什么通过<echo>@{userID}.

 

<sequential> 相当于函数的body 就是你这个可以调用常用ant tag 如何copy javac mkdir jar war 等

 

补充链接

http://lhq1013.iteye.com/blog/1157234

本文出自 “Development” 博客,请务必保留此出处http://jamesdev.blog.51cto.com/2066624/1611760

ANT之macrodef

标签:macrodef ant

原文地址:http://jamesdev.blog.51cto.com/2066624/1611760

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!