Ant是什么东西(初级)
2013-07-12 06:11
239 查看
一、简介:
ANT是一个基于Java的生成工具,类似于Make。生成工具在软件开发中用来将源代码和其他输入文件转换为可执行文件的形式(也有可能转换为可安装的产品映像形式)。随着应用程序的生成过程变得更加复杂,确保在每次生成期间都使用精确相同的生成步骤,同时实现尽可能多的自动化,以便及时产生一致的生成版本。
二、ANT如何工作
在安装好ant的环境中执行命令 ant,ant会开始在当前目录寻找build.xml文件(与Makefile文件类似),然后根据build.xml里定义的规则来生成工程。
三、buildfile(build.xml)
实例如下
<project name="MyProject" default="dist" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
buildfile是XML文件,每个buildfile包含一个project节点(根节点),至少一个Target元素,以及任意个Property元素。
四、Targets
Target对象组织一组要执行的命令(也叫Task)。例如:
<target name="
compile
" description="compile the source" >
<javac srcdir="${src}" destdir="${build}"/>
</target>
执行ant命令时,可以通过指定target名来控制执行某一组命令。例如:ant clean
可执行命令列表:http://ant.apache.org/manual/tasklist.html。
自定义可执行命令方法:http://ant.apache.org/manual/develop.html#writingowntask
五、Property
Property标签是用来自定义生成过程,以及简化字符串(类似于C语言里的宏定义)的工具。
内置Property,无需定义,可以直接使用的属性
basedir the absolute path of the project's basedir (as set with the basedir attribute of <project>).
ant.file the absolute path of the buildfile.
ant.version the version of Ant
ant.project.name the name of the project that is currently executing;
it is set in the name attribute of <project>.
ant.project.default-target
the name of the currently executing project's
default target; it is set via the default
attribute of <project>.
ant.project.invoked-targets
a comma separated list of the targets that have
been specified on the command line (the IDE,
an <ant> task ...) when invoking the current
project.
ant.java.version the JVM version Ant detected; currently it can hold
the values "1.2", "1.3",
"1.4", "1.5" and "1.6".
ant.core.lib the absolute path of the
参考资料
Ant命令总结: http://www.blogjava.net/sutao/articles/133961.html
Ant官网:http://ant.apache.org/
Ant帮助文档:http://ant.apache.org/manual/
ANT是一个基于Java的生成工具,类似于Make。生成工具在软件开发中用来将源代码和其他输入文件转换为可执行文件的形式(也有可能转换为可安装的产品映像形式)。随着应用程序的生成过程变得更加复杂,确保在每次生成期间都使用精确相同的生成步骤,同时实现尽可能多的自动化,以便及时产生一致的生成版本。
二、ANT如何工作
在安装好ant的环境中执行命令 ant,ant会开始在当前目录寻找build.xml文件(与Makefile文件类似),然后根据build.xml里定义的规则来生成工程。
三、buildfile(build.xml)
实例如下
<project name="MyProject" default="dist" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
buildfile是XML文件,每个buildfile包含一个project节点(根节点),至少一个Target元素,以及任意个Property元素。
四、Targets
Target对象组织一组要执行的命令(也叫Task)。例如:
<target name="
compile
" description="compile the source" >
<javac srcdir="${src}" destdir="${build}"/>
</target>
执行ant命令时,可以通过指定target名来控制执行某一组命令。例如:ant clean
可执行命令列表:http://ant.apache.org/manual/tasklist.html。
自定义可执行命令方法:http://ant.apache.org/manual/develop.html#writingowntask
五、Property
Property标签是用来自定义生成过程,以及简化字符串(类似于C语言里的宏定义)的工具。
内置Property,无需定义,可以直接使用的属性
basedir the absolute path of the project's basedir (as set with the basedir attribute of <project>).
ant.file the absolute path of the buildfile.
ant.version the version of Ant
ant.project.name the name of the project that is currently executing;
it is set in the name attribute of <project>.
ant.project.default-target
the name of the currently executing project's
default target; it is set via the default
attribute of <project>.
ant.project.invoked-targets
a comma separated list of the targets that have
been specified on the command line (the IDE,
an <ant> task ...) when invoking the current
project.
ant.java.version the JVM version Ant detected; currently it can hold
the values "1.2", "1.3",
"1.4", "1.5" and "1.6".
ant.core.lib the absolute path of the
ant.jarfile.
ant.home home directory of Ant
ant.library.dir the directory that has been used to load Ant's jars from. In most cases this is ANT_HOME/lib.
参考资料
Ant命令总结: http://www.blogjava.net/sutao/articles/133961.html
Ant官网:http://ant.apache.org/
Ant帮助文档:http://ant.apache.org/manual/
相关文章推荐
- Ant是什么东西(初级)
- python中with关键字是个什么东西
- 到底DB2 catalog是什么东西?
- 我爱天文 - 初级天文爱好者理想的天文望远镜是什么?
- CTF---Web入门第一题 what a fuck!这是什么鬼东西?
- 使用ANT编译--实现外部传参(多渠道替换)、批处理打包------第二步什么是ANT,如何使用ANT命令为Android项目打包
- 微软CSS,GCR半日游-->学了一样东西,什么叫做灰头土脸
- struts2中的session到底是个什么东西
- 找的runtime最基本的一些东西,比看大神们的什么机制解释简单(大神们的东西看完还是蒙逼)
- 域名注册告诉你域名是什么东西
- uoj#87. mx的仙人掌 //圆方树或者别的什么东西
- 原理 zip文件到底是个什么东西
- 怎么样才能在淘宝上买/卖东西啊?有什么步骤和要求啊?
- IE8的"WebSlices"是什么东西
- 什么东西补肾
- 判定表?决策表?什么东西两个名字
- 【程序员的操蛋生活之】心里有什么,看见的东西就是什么!
- 做事就像做人一样,什么事情都要认真,包括打球,不然时间长了就会失去最宝贵的东西,别人对你的信任!
- 有关MAC FIR v5.1的一点东西,也许除了我没有人能看懂写得是什么……
- 素数是个什么东西 prime number