`
yikaicheng_happy
  • 浏览: 7569 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
最近访客 更多访客>>
社区版块
存档分类
最新评论

ant入门

阅读更多
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.

 

Properties

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 "$$".

Built-in Properties

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入门-ant入门pdf

    《Ant入门》是一本专为初学者设计的电子书,主要涵盖了Apache Ant这一构建工具的基础知识和使用方法。Ant是Java开发中广泛使用的自动化构建工具,由Apache软件基金会开发,其设计目标是简化项目构建过程,使开发者...

    Ant 入门资料(完整版)

    这个"Ant入门资料(完整版)"包含了丰富的学习资源,帮助初学者快速掌握Ant的基本概念、用法以及实际应用。 《JUnitAnt_Simp(中文).CHM》:这是一部关于Ant和JUnit的中文手册,JUnit是Java编程语言中的一个单元...

    ant入门小实例练习

    在“ant入门小实例练习”中,我们可以探索Ant的基本用法和核心概念。首先,你需要了解Ant的配置文件`build.xml`,这是整个构建过程的蓝图,定义了一系列的构建目标和任务。每个目标是由一系列的任务(tasks)组成的...

    初学者ant入门级小实例

    以上就是Ant入门的一些基本知识点,通过这个“myant01”实例,你可以动手实践这些概念,逐步熟悉Ant的工作方式。随着经验的积累,你会发现Ant是一个强大且灵活的构建工具,能够满足各种复杂的项目构建需求。

    ant入门资料.快速上手

    ### Ant入门资料:快速上手 #### 一、Ant简介 **1.1 什么是Ant** Apache Ant 是一个Java环境下的构建工具,主要用于自动化编译、测试、部署等任务。它采用XML格式来定义构建过程,使开发者能够通过简单的配置文件...

    ant入门教程,适合初学者

    Ant 入门教程 Ant 是一种基于 Java 和 XML 的 build 工具,在软件开发中发挥着重要作用。本教程旨在为初学者提供一个系统的 Ant 入门指南,涵盖了 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使用指南-Ant入门手册 #### 一、Ant是什么? Apache Ant 是一款开源的 Java 构建工具,它的名字来源于“Another Neat Tool”的首字母缩写。Ant 能够帮助开发者自动化构建过程,包括编译源代码、运行测试、...

    Ant 入门

    NULL 博文链接:https://teddywang.iteye.com/blog/722248

    Ant入门与进阶

    ### Ant入门与进阶知识点详解 #### 一、Ant简介 **1.1 Ant的起源** Ant是由James Duncan Davidson在1998年创建的一种构建工具。当时,James尝试使用现有的构建工具(如GNU Make、批处理文件和shell脚本)来创建一...

    Ant入门与进阶ant

    【Ant入门与进阶】Ant,全称Apache Ant,是一个基于Java的构建工具,由James Duncan Davidson在1998年创建,旨在解决当时构建工具无法有效处理跨平台构建问题的困境。Ant的设计灵感来源于其小巧却强大的特性,就像它...

    ant入门书籍 ant使用指南

    ant入门书籍,带你走入ant的世界。ant使用指南,工具介绍

    Ant入门学习手册(java ant教程)

    ### Ant入门学习手册:深入解析Java项目构建利器 #### Ant:Java项目构建的灵活与高效之选 在软件开发领域,构建工具扮演着至关重要的角色,它们负责将源代码及其它资源转换为可执行文件或产品镜像。Ant,作为一款...

    Ant_的最完整build.xml解释,Ant入门与进阶

    《Ant的最完整build.xml解释:Ant入门与进阶》 Ant,作为Java世界中的一个构建工具,由Apache软件基金会开发,是项目管理和自动化构建的重要工具。它通过XML定义的build.xml文件,来描述项目的构建过程,包括编译、...

    ant入门编写例子,非常简单实效哦

    标题“ant入门编写例子,非常简单实效哦”指的是这篇内容将向初学者展示如何使用Ant进行基本的项目构建。Ant的入门通常包括创建build.xml文件,设置项目属性,定义任务,以及引入依赖等步骤。这个例子可能是为了帮助...

    Ant 入门讲解视频

    Ant是Apache软件基金会下的一个...通过观看"Ant入门讲解视频",你可以进一步了解Ant的使用方法和实践案例,结合文档`Ant 入门讲解视频(22分03秒).doc`深入学习,配合`ant.exe`进行实际操作,快速掌握Ant的基本技能。

Global site tag (gtag.js) - Google Analytics