ant是一个基于java的自动化脚本引擎,脚本的格式为xml.
ant脚本的编译顺序:
Ant tries to execute the targets in the depends
attribute in the order they appear (from left to right). Keep in mind that it is possible that a target can get executed earlier when an earlier target depends on it:
<target name="A"/>
<target name="B" depends="A"/>
<target name="C" depends="B"/>
<target name="D" depends="C,B,A"/>
Suppose we want to execute target D. From its depends
attribute, you might think that first target C, then B and then A is executed. Wrong! C depends on B, and B depends on A, so first A is executed, then B, then C, and finally D.
A project can have a set of properties. These might be set in the buildfile by the property task, or might be set outside Ant. A property has a name and a value; the name is case-sensitive. Properties may be used in the value of task attributes. This is done by placing the property name between "${
" and "}
" in the attribute value. For example, if there is a "builddir" property with the value "build", then this could be used in an attribute like this: ${builddir}/classes
. This is resolved at run-time as build/classes
.
In the event you should need to include this construct literally (i.e. without property substitutions), simply "escape" the '$' character by doubling it. To continue the previous example:
<echo>$${builddir}=${builddir}</echo>
will echo this message:
${builddir}=build/classes
In order to maintain backward compatibility with older Ant releases, a single '$' character encountered apart from a property-like construct (including a matched pair of french braces) will be interpreted literally; that is, as '$'. The "correct" way to specify this literal character, however, is by using the escaping mechanism unconditionally, so that "$$" is obtained by specifying "$$$$". Mixing the two approaches yields unpredictable results, as "$$$" results in "$$".
Ant provides access to all system properties as if they had been defined using a <property>
task. For example, ${os.name}
expands to the name of the operating system.
For a list of system properties see the Javadoc of System.getProperties.
In addition, Ant has some built-in properties:
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.java.version the JVM version Ant detected; currently it can hold
the values "1.2", "1.3", "1.4" and "1.5".
There is also another property, but this is set by the launcher script and therefore maybe not set inside IDEs:
ant.home home directory of Ant
示例:
<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>
=======================================================================
<project basedir="." default="war" name="ucdcenter">
<property name="dist.war" value="../dist/ucdcenter.war" />
<property name="dist.webroot" value="../dist/WebRoot" />
<property name="dist.webinf.dir" value="${dist.webroot}/WEB-INF" />
<property name="lib.dir" value="../lib"/>
<property name="web.class.dir" value="WebRoot/WEB-INF/classes" />
<property name="j2eelib.dir" value="../j2ee1.4lib" />
<property environment="env" />
<property name="business.location" value="../business"/>
<property name="debuglevel" value="source,lines,vars" />
<property name="target" value="1.5" />
<property name="source" value="1.5" />
<property name="compiler.args" value="-encoding UTF-8" />
<path id="j2ee.libraryclasspath">
<fileset dir="${j2eelib.dir}" includes="**/*.jar" />
</path>
<path id="ucdcenter.classpath">
<pathelement location="${web.class.dir}" />
<path refid="j2ee.libraryclasspath" />
<fileset dir="${lib.dir}" includes="**/*.jar" />
</path>
<target name="init">
<delete dir="../dist" />
<mkdir dir="../dist" />
<copy includeemptydirs="false" todir="${dist.webroot}">
<fileset dir="WebRoot" excludes="**/*.launch, **/*.java" />
</copy>
<copy includeemptydirs="false" todir="${dist.webinf.dir}/classes">
<fileset dir="src" excludes="**/*.launch, **/*.java" />
<fileset dir="config" excludes="**/*.launch, **/*.java" />
</copy>
<copy includeemptydirs="false" todir="${dist.webinf.dir}/lib/">
<fileset dir="${lib.dir}" includes="*.jar"/>
<fileset dir="${lib.dir}/j2ee" includes="**/*.jar"/>
<fileset dir="${lib.dir}/xfire" includes="**/*.jar"/>
<fileset dir="${lib.dir}/pdf" includes="**/*.jar"/>
<fileset dir="${lib.dir}/activemq" includes="**/*.jar"/>
<fileset dir="${lib.dir}/springmodules" includes="**/*.jar"/>
</copy>
</target>
<target name="build-subprojects">
<ant antfile="${business.location}/build.xml" inheritAll="false" target="build-project"/>
</target>
<target depends="init,build-subprojects" name="build-project">
<echo message="${ant.project.name}: ${ant.file}" />
<javac debug="true" debuglevel="${debuglevel}" destdir="${dist.webinf.dir}/classes" source="${source}" target="${target}">
<compilerarg line="${compiler.args}" />
<src path="." />
<classpath refid="ucdcenter.classpath" />
</javac>
</target>
<target name="war" depends="build-project" description="war ucdcenter">
<tstamp>
<format property="datestamp" pattern="yyyy-MM-dd" />
</tstamp>
<war destfile="${dist.war}" webxml="${dist.webinf.dir}/web.xml" basedir="${dist.webroot}" excludes="**/web.xml">
</war>
</target>
</project>
分享到:
相关推荐
《Ant入门》是一本专为初学者设计的电子书,主要涵盖了Apache Ant这一构建工具的基础知识和使用方法。Ant是Java开发中广泛使用的自动化构建工具,由Apache软件基金会开发,其设计目标是简化项目构建过程,使开发者...
这个"Ant入门资料(完整版)"包含了丰富的学习资源,帮助初学者快速掌握Ant的基本概念、用法以及实际应用。 《JUnitAnt_Simp(中文).CHM》:这是一部关于Ant和JUnit的中文手册,JUnit是Java编程语言中的一个单元...
在“ant入门小实例练习”中,我们可以探索Ant的基本用法和核心概念。首先,你需要了解Ant的配置文件`build.xml`,这是整个构建过程的蓝图,定义了一系列的构建目标和任务。每个目标是由一系列的任务(tasks)组成的...
以上就是Ant入门的一些基本知识点,通过这个“myant01”实例,你可以动手实践这些概念,逐步熟悉Ant的工作方式。随着经验的积累,你会发现Ant是一个强大且灵活的构建工具,能够满足各种复杂的项目构建需求。
### Ant入门资料:快速上手 #### 一、Ant简介 **1.1 什么是Ant** Apache Ant 是一个Java环境下的构建工具,主要用于自动化编译、测试、部署等任务。它采用XML格式来定义构建过程,使开发者能够通过简单的配置文件...
Ant 入门教程 Ant 是一种基于 Java 和 XML 的 build 工具,在软件开发中发挥着重要作用。本教程旨在为初学者提供一个系统的 Ant 入门指南,涵盖了 Ant 的安装、环境配置、命令解释等方面。 Ant 的安装 要使用 Ant...
ant的简单入门教程 1、ant介绍;2、ant安装;3、第一个ant脚本;4、整合ant;5、ant进阶;6、常用task;7、控制流程;8、实例分析;9、如何继续学习;10、ant使用cvs实例;11、Q&A
### Ant使用指南-Ant入门手册 #### 一、Ant是什么? Apache Ant 是一款开源的 Java 构建工具,它的名字来源于“Another Neat Tool”的首字母缩写。Ant 能够帮助开发者自动化构建过程,包括编译源代码、运行测试、...
NULL 博文链接:https://teddywang.iteye.com/blog/722248
ant入门书籍,带你走入ant的世界。ant使用指南,工具介绍
这个"Ant入门与进阶"的主题涵盖了从初识Ant到深入掌握其高级特性的全过程,对于Java开发者来说,这是一个至关重要的工具,因为它是构建Java项目的主要方式之一。 Ant的名称来源于“蚂蚁”,寓意其能够像蚂蚁一样...
《Ant的最完整build.xml解释:Ant入门与进阶》 Ant,作为Java世界中的一个构建工具,由Apache软件基金会开发,是项目管理和自动化构建的重要工具。它通过XML定义的build.xml文件,来描述项目的构建过程,包括编译、...
标题“ant入门编写例子,非常简单实效哦”指的是这篇内容将向初学者展示如何使用Ant进行基本的项目构建。Ant的入门通常包括创建build.xml文件,设置项目属性,定义任务,以及引入依赖等步骤。这个例子可能是为了帮助...
Ant是Apache软件基金会下的一个...通过观看"Ant入门讲解视频",你可以进一步了解Ant的使用方法和实践案例,结合文档`Ant 入门讲解视频(22分03秒).doc`深入学习,配合`ant.exe`进行实际操作,快速掌握Ant的基本技能。