码迷,mamicode.com
首页 > 其他好文 > 详细

ANT basic

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

标签:ant

ant build file 用于 java 自动运行脚本类似于linux 的bash 和 windows dos script. 常用于自动deploy war ear file to server.

ant 是基于xml file 通过tag 命令执行

 

一个build.xml 至少包含project and target tag

ant build file at least has one <project> <target>

<project> require
attributes: name default basedir

<target>  require
attributes: name depends?????? <target name=‘test‘ depends=‘package,compile‘

<echo> print the msg out on console

 

 

######### build file 匹配模式

pattern


? - Matches one character only.


* - Matches zero or many characters.


** - Matches zero or many directories recursively.

 

######常用标签

########<property tag>

<property> define variable


###default properties
ant.file The full location of the build file.
ant.version The version of the Apache Ant installation.
basedir The basedir of the build, as specified in the basedir attribute of the project element.
ant.java.version The version of the JDK that is used by Ant.
ant.project.name The name of the project, as specified in the name atrribute of the project element.
ant.project.default-target The default target of the current project.
ant.project.invoked-targets Comma separated list of the targets that were invoked in the current project.
ant.core.lib The full location of the Ant jar file.
ant.home The home directory of Ant installation.
ant.library.dir The home directory for Ant library files - typically ANT_HOME/lib folder.

 

<property> tag 可以定义在build file 为了可维护和提高代码robust 可以将一些属性定义在build.properties 文件里面。 通过 <property file="build.properties"> 引用build.properties 的内容。

 

 

#### <fileset> 指定文件夹下选择需要的文件。 include tag 表示包含通过pattern 来选择 excluude 就是排除哪些文件


<fileset> collection of files 


<fileset dir="${src}" casesensitive="yes">
   <include name="**/*.java"/>
   <exclude name="**/*Stub*"/>
</fileset>


<path> 就是一个路径集合 在<path> 下通过<pathelement 说明具体路径 其中location 路径属性是特指具体某一个路径 path 属性是泛指 可以是一个path 或者 path list


<path id="test.classpath">
 <pathelement path="c:/java/jdk1.7.0/jre/lib"></pathelement>
 <pathelement location="C:/eclipse 4.2/plugins/org.junit_4.10.0.v4_10_0_v20120426-0900/junit.jar"></pathelement>
 <pathelement location="C:/eclipse 4.2/plugins/org.hamcrest.core_1.1.0.v20090501071000.jar"></pathelement>
 
</path>

 

####<javac>  compile

<javac destdir="${class.dir}" >
  <src refid="compilejava"></src>
  <classpath refid="test.classpath"></classpath>
 </javac>


<jar destfile="${libs}/ant.jar" basedir="${class.dir}">
 
 
 </jar>

 

补充连接详细例子和部分tags

http://blog.csdn.net/yangdayin/article/details/7681567

 

http://www.cnblogs.com/xionghui/archive/2012/03/13/2393679.html

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

ANT basic

标签:ant

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

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